很多配置过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 都能访问。

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

转载于:https://www.cnblogs.com/wujf-myblog/p/10592423.html

nginx强制使用https访问(多站点多域名配置)相关推荐

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

    nginx强制使用https访问(http跳转到https) 基于nginx搭建了一个https访问的虚拟主机,监听的域名是test.com,但是很多用户不清楚https和http的区别,会很容易敲成 ...

  2. 配置nginx代理实现https访问

    配置nginx代理实现https访问 Google宣布从Chrome网络浏览器的下一个稳定版本(90)开始,将为地址栏中输入的所有URL网址默认选择HTTPS协议.这意味着未启用HTTPS的网站的打开 ...

  3. 解决:VUE nginx 部署 SSL https访问 WebSocket 问题

    报错1. Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a p ...

  4. 宝塔上的wordpress站点更换域名+配置SSL+改版百度收录

    前言 好久没写文章了,甚是想念,近半年来发生了很多事情,心态也变了很多. 这个博客自创办以来,原域名叫"is-hash.com",是我2019年的突发奇想注册此域名,"i ...

  5. Nginx如何支持HTTPS?手把手教会你每一步操作都贼简单,kafka和rabbitmq区别面试题

    随着我们网站用户的增多,我们会逐渐意识到HTTPS加密的重要性.在不修改现有代码的情况下,要从HTTP升级到HTTPS,让Nginx支持HTTPS是个很好的选择.今天我们来讲下如何从Nginx入手,从 ...

  6. Nginx如何支持HTTPS?手把手教贼简单!

    随着我们网站用户的增多,我们会逐渐意识到HTTPS加密的重要性.在不修改现有代码的情况下,要从HTTP升级到HTTPS,让Nginx支持HTTPS是个很好的选择.今天我们来讲下如何从Nginx入手,从 ...

  7. linux服务器配置https访问

    如果要配置https访问,就是要安装配置SSL证书.目的就是加强网站的安全性. 但是大部分SSL证书是要收费的! 福利来了,下将介绍如何使用最大SSL证书服务商的免费证书:赛门铁克Symantec/D ...

  8. 【Spring】配置SpringBoot同时支持http和https访问

    配置https访问 生成证书 如果配置了JAVA开发环境,可以使用keytool命令生成证书.我们打开控制台,输入: keytool -genkey -alias tomcat -dname &quo ...

  9. java 调用tomcat api,Tomcat采用双向认证https协议通过JavaAPI调用(一)配置SSL

    双向认证(个人理解): 客户端认证: 客户端通过浏览器访问某一网站时,如果该网站为HTTPS网站,浏览器会自动检测系统中是否存在该网站的信任证书,如果没有信任证书,浏览器一般会拒绝访问,IE会有一个继 ...

最新文章

  1. 未来的全能保姆机器人作文_保姆机器人作文500字
  2. mysql可以关联视图_Mysql 五: 数据库自关联、视图
  3. Java初学者推荐学习书籍free下载
  4. OpenDNS,独特的免费DNS
  5. 数据库原理与应用(SQL Server)笔记 第四章 嵌套查询和其他查询子句
  6. 如何找到 SAP Spartacus 里某个 Component TypeScript 编译后生成的 JavaScript 位置
  7. Spark Run本地设计模式
  8. 编写自定义的AssertJ断言
  9. Spring MVC访问不到静态资源
  10. 2016专接本c语言真题_专科三年记录+自己学习专接本历程
  11. 双机热备、集群及高可用性入门转载
  12. 汇编64位无法生成可用exe_MASM学习x86汇编语言2 寄存器、伪指令与程序调试
  13. HBase 写优化之 BulkLoad 实现数据快速入库
  14. Latex的使用模板
  15. Gamesalad借QQ游戏无线平台进军中国
  16. 我的大学四年到毕业工作5年的学习路线资源汇总
  17. java二重积分_java 版本二重积分计算
  18. 5.3 - 抽屉新热榜
  19. fiddler 抓包显示 ERR_TUNNEL_CONNECTION_FAILED
  20. 来到 “鹅厂” 的 2019

热门文章

  1. python【蓝桥杯vip练习题库】ADV-303 数组求和
  2. [BZOJ 2523][Ctsc2001]聪明的学生(递归)
  3. ajax核心代码提交,ajax表单在Asp.net核心提交后的RedirectToAction
  4. java多线程面试_面试之JAVA多线程
  5. 高版本转低版本_Tekla高版本模型转低版本模型插件
  6. 如何进行网络推广教大家在网站排名变差该如何进行查找问题所在?
  7. 提升软文营销曝光量可从这几方面着手操作
  8. android test.apk,app-debug.apk和app-debug-androidTest.apk在安装macaca-android模块的时候build失败...
  9. java编程50实例_java编程实例大全及详解谜底(50例).doc
  10. neat算法——本质就是遗传算法用于神经网络的自动构建