很多配置过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. 如鹏网JAVA培训笔记1(晓伟整理)

    JDK(Java Developmet Kit) JRE(Java RunTime Environment)的区别: JRE只有运行JAVA程序的环境,没有开发相关的工具;JDK=JRE+开发相关的工 ...

  2. 第三次组队赛 (DFS&BFS)

    网站:CSUST 8月1日 先总结下,不得不说死的很惨,又是第三就不说了,一共7道题,AC了5道,但是有一个组三个人是做的个人赛,有两人AK了.......Orz,然后深搜还是大问题,宽搜倒是不急了. ...

  3. 消息队列Rabbit安装

    先安装elang 再安装Rabbit *Rabbit安装路径不能有空格 安装完成

  4. POJ 2008

    这道题,说实话,细节很多.不过,我没想到,光细节就能搞死人了... 参考了http://www.cppblog.com/varg-vikernes/archive/2010/03/12/109559. ...

  5. linux下安装rar解压包

    直接解压时出现的问题如下 原因:使用rar命令需要安装WinRAR 1.在本机下载好解压,然后将解压包拖到linux上 2.进行安装,在rar目录想直接make

  6. bzoj4887: [Tjoi2017]可乐

    一眼暴力宽搜(最近比赛想暴力想疯了... 很明显的矩乘,然后自爆可以看作走向向一个无出边的点 然后没啥难的了吧. #include<cstdio> #include<iostream ...

  7. Swift3.0 split函数切割字符串

    我们先看函数的原型: public func split(separator: Self.Iterator.Element, maxSplits: Int = default, omittingEmp ...

  8. B1237 [SCOI2008]配对 贪心 + dp

    我刚开始,我打眼一看:哇!网络流大水题,直接费用流板子,建边跟zz一样.结果看了一眼数据范围...gg,luogu上只能得30,直接建边就是n^2,1e5根本过不了.咋办,只能另谋出路.想不出来,看题 ...

  9. 05.使用jdk发布webservice服务

    无论服务端是用什么写的,使用框架写的还是用jdk写的,它都会发布出来这样一个东西.主要你遵循咱们这七个步骤来走就可以调用了. 咱们现在转换一下角色,自己发布一个服务让别人去调.怎么来发布一个服务? 我 ...

  10. 【BZOJ3218】【UOJ#77】a + b Problem

    题目 题目在这里 思路&做法 明显的最小割(其实是之前做过一道类似的题) S向每一个格子连容量为\(b_i\)的边 每一个格子向T连容量为\(w_i\)的边 对于格子\(i\)向满足条件的格子 ...