很多配置过https模板的人都知道,配置https 时 ,站在用户的角度http 和https 的区别根本不清楚。有时候敲 http 时会出现 404 错误,而实际上我们是https.

有朋友找我配置一个多站点多域名,想着工作不是很忙,就花点时间给他配置下。

他的需求是这样的:

  1.2个项目放在同一台服务器

  2.多站点,多域名(也就是说不同的域名访问不同的项目,且其中一个项目使用https)

下面是我跟她配置的

server {
listen 80;
server_name 47.106.178.XXX www.oyuanxing.com wx.oyuanxing.com; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / { rewrite ^(.*)$ https://$host$1 permanent;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
root /usr/share/nginx/html/OGO/;
index index.html index.htm index.php;
} error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/OGO/;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html/OGO/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/OGO/$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} server {
listen 443 ssl;
server_name 47.106.178.XXX www.oyuanxing.com wx.oyuanxing.com; ssl on;
ssl_certificate cert/1968881__oyuanxing.com.pem;
ssl_certificate_key cert/1968881__oyuanxing.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
} root /usr/share/nginx/html/OGO/;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/OGO/;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html/OGO/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/OGO/$fastcgi_script_name;
include fastcgi_params;
}
} server {
listen 80;
server_name 47.106.178.XXX m.lhmhcc.com ; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / { if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
root /usr/share/nginx/html/TOUTOU/;
index index.html index.htm index.php;
} error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/TOUTOU/;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html/TOUTOU/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/TOUTOU/$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

  若是不加上面那句加粗的重写规则,那么http 和 https 都能访问。

此时多站点 多域名 就配好了。

nginx强制使用https访问(多站点多域名配置)的更多相关文章

  1. nginx强制使用https访问(http跳转到https)

    Nginx 的 Location 从零开始配置 - 市民 - SegmentFault 思否https://segmentfault.com/a/1190000009651161 nginx配置loc ...

  2. centos7安装tengine强制使用HTTPS访问

    操作系统:centos7.2 x64tengine:Tengine/2.2.0主机IP: 10.0.0.12 一.安装tengine 1.1 下载源码安装包 1.1.1 源码包pcre-8.40   ...

  3. nginx 设置自签名证书以及设置网址http强制转https访问

    自签名证书可以在自己的内网环境或者非对外环境使用,保证通信安装 1.生产证书 直接使用脚本生产: 中途会提示书如1次域名和4次密码,把一下文件保存为sh文件,赋予x权限后 直接执行,根据提示输入. # ...

  4. docker下安装nginx并实现https访问

    一.启动容器 docker run --detach --name wx-nginx -p 443:443 -p 80:80 -v /home/nginx/data:/usr/share/nginx/ ...

  5. C++模拟Http/Https访问web站点

    一.概述 1.Http与Https的区别与联系 在OSI参考模型中Http与Https均属于应用层协议.Http即Hypertext Transfer Protocol,超文本传输协议:而Https为 ...

  6. 项目通过nginx强转为https访问后,代码中重定向的连接又变成了http协议,导致点击页面按钮,后台逻辑处理完后重定向报错了

    修改如下,需要在nginx对应的server下的location中增加配置,使重定向的地址协议取当前链接的协议,而不是nginx访问tomcat的协议,因为nginx访问tomcat是http的,并没 ...

  7. nginx反向代理https访问502, nginx反向代理, 支持SNI的https回源,SNI源点,nginx反向代理报错

    正常nginx配置了SSL是可以通过HTTPS访问后端的,但是对有配置SNI + https后端的支持有点麻烦. 编译安装nginx后,看一下是否支持SNI /usr/local/nginx/sbin ...

  8. 记一次nginx强制将https请求重定向http

    公司要做小程序,但是发现小程序只允许https请求 所以查了查资料使用nginx重定向请求得方式做 以下是过程: 阿里云ssl证书管理控制台申请ssl证书 下载nginx 证书: 解压后得到后缀为ke ...

  9. iOS 9/10强制使用https访问网络,使用了第三方SDK的应用需要配置的信息

    2017年01月01日起苹果将全面禁止使用http来访问网络. 网上扒了一些资源,解决方法还是有的,但是都不确定是否可以通过审核,毕竟实践才是检验真理的唯一标准. 后续如果上线成功,再来分享. 如果应 ...

随机推荐

  1. 0301mysql数据库建表情况

    转自博客:http://blog.csdn.net/dreamcode/article/details/8557197 一. 表设计 库名.表名.字段名必须使用小写字母,“_”分割. 库名.表名.字段 ...

  2. Eclipse安装Jetty插件(Web容器)

    Eclipse除了安装Tomcat插件外,还可以安装Jetty,相对来说Jetty比Tomcat配置简单. Tomcat安装及配置:http://www.cnblogs.com/EasonJim/p/ ...

  3. Mycat连接数据库之后导致表名全小写的问题分析研究

    初步研究:通过部署发现在Mycat中部署逻辑表表名大小写混合时,在Mycat连接后出现全变小.容易造成错误逻辑表(按混合表名创建物理表): 可能拯救的方法: 1.Linux下部署安装MySQL,默认不 ...

  4. Visual Studio 2013 与 14

    Visual Studio 2013 与 14 假设有曾经版本号的 Visual Studio.再想安装 Visual Studio 14 CTP,默认情况下是不行的. 假设一定要装,当然也是能够的. ...

  5. 很不错的点餐系统应用ios源代码完整版

    该源代码是一款很不错的点餐系统应用,应用源代码齐全,执行起来很不错,基本实现了点餐的一些经常使用的功能,并且界面设计地也很不错,是一个不错的ios应用学习的样例,喜欢的朋友能够下载学习看看,很多其它i ...

  6. [ Javascript ] 内存泄露以及循环引用解析

    内存泄露 在javascript中,我们非常少去关注内存的管理. 我们创建变量,使用变量,浏览器关注这些底层的细节都显得非常正常. 可是当应用程序变得越来越复杂而且ajax化之后,或者用户在一个页面停 ...

  7. HDU4300-Clairewd’s message-KMP

    题目链接:pid=4300">http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目意思真的非常难读懂. 题意:给定两组字符串,第一组仅仅有 ...

  8. 2016.04.19,英语,《Vocabulary Builder》Unit 16

    top, comes from topos, the Greek word for 'place'. ectopic: [ek'tɑːpɪk] adj. [医]异位的,异常的 topical: ['t ...

  9. 如何将dmp文件导入到自己的oracle数据库中

    1.首先,我们可以先建立自己的一个用户表空间,创建表空间的格式如下: create tablespace test(表空间的名字) datafile 'D:\oracle\product\10.2.0 ...

  10. 6.11Realm简介

    CasRealm 统一认证授权中心  跟单点登录有关的.IniRealm 静态文件