当前位置:首页 » 互联网资讯 » 正文

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

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

方法一

rewrite ^(.*)$ https://$host$1 permanent;

方法二

适用于 生成 网站 APP8app开发生成0端口和443 配置在同一个 server{}内

if ($server_port = 80) {
      rewrite ^(.*)$ https://$host$1 permanent;
}

其他情况, 站点绑定很多域名,只让某个域名跳转:

set $redirect_https 1;
if ($server_port = 80) {
   set $redirect_https "${redirect_https}2";
}
if ($http_host = 'www.yourdomain.com') {
   set $redirect_https "${redirect_https}3";
}
if ($http_host = 'yourdomain.com') {
   set $redirect_https "${redirect_https}3";
}

if ($redirect_https = "123") {
rewrite ^(.*)$ https://$host$1 permanent;
}

示例

server {
        listen       80;
        server_name  www.getssl.cc;
        rewrite ^ https://$http_host$request_uri? permanent;
}

server {
        listen 443;
        ssl on;
        ssl_certificate /etc/ssl/cacert.pem;
        ssl_certificate_key /etc/ssl/privkey.pem;
        server_name www.yourdomain.com;  

        
        server_tokens off;

        location / {
          
                fastcgi_param   HTTPS               on;
                fastcgi_param   HTTP_SCHEME         https;

        }
        
}

编辑:娜娜,如若转载,请注明出处:https://www.yimenapp.com/kb-yimen/4895/

部分内容来自网络投稿,如有侵权联系立删

未经允许不得转载:一门应用 » Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置
分享到

相关推荐

联系我们

微信公众号

yimendabao

关注官方微信,了解最新资讯

客服QQ
4001658508

企业QQ,点击发起咨询