Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置

[复制链接]
希望工程bossLv.7 显示全部楼层 发表于 2020-4-24 16:29:52 |阅读模式 打印 上一主题 下一主题
苹果上架
Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置

1.方法一
  1. rewrite ^(.*)$ https://$host$1 permanent;
复制代码


2.方法二
适用于 80端口和443 配置在同一个 server{}内
  1. if ($server_port = 80) {
  2.       rewrite ^(.*)$ https://$host$1 permanent;
  3. }
复制代码


其他情况, 站点绑定很多域名,只让某个域名跳转:
  1. set $redirect_https 1;
  2. if ($server_port = 80) {
  3.    set $redirect_https "${redirect_https}2";
  4. }
  5. if ($http_host = 'www.yourdomain.com') {
  6.    set $redirect_https "${redirect_https}3";
  7. }
  8. if ($http_host = 'yourdomain.com') {
  9.    set $redirect_https "${redirect_https}3";
  10. }
  11. if ($redirect_https = "123") {
  12. rewrite ^(.*)$ https://$host$1 permanent;
  13. }
复制代码


示例
  1. server {
  2.         listen       80;
  3.         server_name  www.getssl.cc;
  4.         rewrite ^ https://$http_host$request_uri? permanent;
  5. }
  6. server {
  7.         listen 443;
  8.         ssl on;
  9.         ssl_certificate /etc/ssl/cacert.pem;
  10.         ssl_certificate_key /etc/ssl/privkey.pem;
  11.         server_name www.getssl.cn;  
  12.        
  13.         server_tokens off;
  14.         location / {
  15.           
  16.                 fastcgi_param   HTTPS               on;
  17.                 fastcgi_param   HTTP_SCHEME         https;
  18.         }
  19.        
  20. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

一门APP打包致力于H5混合APP基础框架领域的前沿探索,专注轻便的移动应用解决方案 提供基于HTML前端页面在各种应用层级的端延展。
  • 官方手机版

  • 微信公众号

  • 微信客服

  • Powered by Discuz! X3.4 | Copyright © 2001-2020, 一门APP. | 一门APP开发平台|热门标签
  • 蜀ICP备17005078号-4 | 川公网安备 51019002001185号 | |成都七扇门科技有限公司