很多配置过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. 【[Offer收割]编程练习赛11 D】排队接水

    [题目链接]:http://hihocoder.com/problemset/problem/1488 [题意] 中文题 [题解] 莫队算法+树状数组; 首先贪心地知道,应该按照时间从小到大的顺序打水 ...

  2. mybatis使用-helloword(一)

    前言 首先感谢https://my.oschina.net/zudajun/blog/665956(jd上也出书了貌似)  这位作者.让自己能系统的看完和理解第一个框架的源码(其实我反复看了4遍以上, ...

  3. E - Just a Hook

    E - Just a Hook HDU 1698 思路:区间修改即可. #include<cstdio> #include<cstring> #include<iostr ...

  4. Spring MVC + Shiro + Redis 实现集群会话管理

    之前用的单机Shiro实现用户单点登陆,基本问题不大,但是集群间的session共享单靠Shiro就不好实现了.所以就借助Redis数据库来实现. 这里Redis的搭建我之前说过,感兴趣的可以去看看: ...

  5. 允许远程访问MySQL的设置

    允许远程访问MySQL的设置 学习了:http://www.cnblogs.com/hyzhou/archive/2011/12/06/2278236.html Windows版本有workbench ...

  6. [CSS3] :empty Selector

    When the element has empty content, you might want to display some text to idicate the compoent is l ...

  7. 开源前夕先给大家赞赏一下我用C语言开发的云贴吧 站点自己主动兼容-移动、手机、PC自己主动兼容云贴吧

    开源前夕先给大家赞赏一下我用C语言开发的移动.手机.PC自己主动兼容云贴吧 - 涨知识属马超懒散,属虎太倔强.十二生肖全了!-转自云寻觅贴吧 转: 涨知识属马超懒散,属虎太倔强.十二生肖全了! -转自 ...

  8. 【Oracle】RAC删除节点

    环境: OS:OEL5.6 RAC:10.2.0.1.0 眼下有rac1.rac2.rac3三个节点,下面是删除rac3节点的具体过程 1.删除rac3节点上的数据库实例 [oracle@rac1 ~ ...

  9. DecimalFormat格式化输出带小数的数字类型

    刚開始 double d = 333333333.333333333; System.out.println(d); 输出结果为3.333333333333333E8 网上找到了DecimalForm ...

  10. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 线段树模拟

    E. Correct Bracket Sequence Editor   Recently Polycarp started to develop a text editor that works o ...