nginx强制使用https访问(多站点多域名配置)
很多配置过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访问(多站点多域名配置)的更多相关文章
- nginx强制使用https访问(http跳转到https)
Nginx 的 Location 从零开始配置 - 市民 - SegmentFault 思否https://segmentfault.com/a/1190000009651161 nginx配置loc ...
- centos7安装tengine强制使用HTTPS访问
操作系统:centos7.2 x64tengine:Tengine/2.2.0主机IP: 10.0.0.12 一.安装tengine 1.1 下载源码安装包 1.1.1 源码包pcre-8.40 ...
- nginx 设置自签名证书以及设置网址http强制转https访问
自签名证书可以在自己的内网环境或者非对外环境使用,保证通信安装 1.生产证书 直接使用脚本生产: 中途会提示书如1次域名和4次密码,把一下文件保存为sh文件,赋予x权限后 直接执行,根据提示输入. # ...
- docker下安装nginx并实现https访问
一.启动容器 docker run --detach --name wx-nginx -p 443:443 -p 80:80 -v /home/nginx/data:/usr/share/nginx/ ...
- C++模拟Http/Https访问web站点
一.概述 1.Http与Https的区别与联系 在OSI参考模型中Http与Https均属于应用层协议.Http即Hypertext Transfer Protocol,超文本传输协议:而Https为 ...
- 项目通过nginx强转为https访问后,代码中重定向的连接又变成了http协议,导致点击页面按钮,后台逻辑处理完后重定向报错了
修改如下,需要在nginx对应的server下的location中增加配置,使重定向的地址协议取当前链接的协议,而不是nginx访问tomcat的协议,因为nginx访问tomcat是http的,并没 ...
- nginx反向代理https访问502, nginx反向代理, 支持SNI的https回源,SNI源点,nginx反向代理报错
正常nginx配置了SSL是可以通过HTTPS访问后端的,但是对有配置SNI + https后端的支持有点麻烦. 编译安装nginx后,看一下是否支持SNI /usr/local/nginx/sbin ...
- 记一次nginx强制将https请求重定向http
公司要做小程序,但是发现小程序只允许https请求 所以查了查资料使用nginx重定向请求得方式做 以下是过程: 阿里云ssl证书管理控制台申请ssl证书 下载nginx 证书: 解压后得到后缀为ke ...
- iOS 9/10强制使用https访问网络,使用了第三方SDK的应用需要配置的信息
2017年01月01日起苹果将全面禁止使用http来访问网络. 网上扒了一些资源,解决方法还是有的,但是都不确定是否可以通过审核,毕竟实践才是检验真理的唯一标准. 后续如果上线成功,再来分享. 如果应 ...
随机推荐
- js给对象onclick事件赋值
1)当方法没有参数时,赋值可以直接用onclick = 方法名 window.onload = function() { $('btnTest').onclick = test; } function ...
- 暑假集训D14总结
%dalao 今天dalao继续来讲课~讲的是一个叫kd树的奇怪东西= = 然而啥都没听懂 考试 今天多校联考,日常炸= = 照例打了前两道题的暴力(T1随便hash一下就水过了啊喂),然后开始推T3 ...
- 1013MySQL监控利器-Innotop
转自 http://www.cnblogs.com/ivictor/p/5101506.html 安装过程中 可以使用 YUM INSTALL INNOTOP进行直接安装 Innotop是一款十分强大 ...
- mysql备份恢复中的常见错误
从A主机备份到B主机 mysqldump -uroot -p vw>vw.sql 现备份数据库文件,需要恢复到目标机B,B的数据库版本为5.5.23,A机器的mysql版本为5.0.2 ...
- [jQuery]jQuery获取URL参数
// jQuery url get parameters function [获取URL的GET参数值]// <code>// var GET = $.urlGet(); //获取URL的 ...
- POJ 1987
T_T为毛会这样子,我的写就是过不了,....... 其实这题不难,很容易想到吧,我一开始也想着用枚举这类方法,但复杂度实在不敢想,没想到,真的是用这种方法.. 今天学了一个叫树的重心,可以使分治的子 ...
- 当使用servlet输出json时,浏览器端jquery的ajax遇到parse error的问题
在使用jquery的ajax进行请求发送并由服务端的servlet返回json格式的数据内容时,假设输出内容没有正确设置,会遇到client浏览器报告parse error的问题.这个问题的解决仅仅须 ...
- 认证 协议 JWT OAuth Session Cookie
本文翻译自Auth-Boss. 如果有翻译的不恰当或不对的地方, 欢迎指出. 成为一个认证老司机, 了解网络上不同的身份认证方法. 本文档的目的是记录和编目Web上的身份验证方法.认证指的是创建一个系 ...
- codetemplate
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templa ...
- python 编写的经纬度坐标转换类
# -*- coding: utf-8 -*- # /** # * 各地图API坐标系统比较与转换; # * WGS84坐标系:即地球坐标系,国际上通用的坐标系.设备一般包含GPS芯片或者北斗芯片获取 ...