首页 > 系统相关 >nginx 强制https

nginx 强制https

时间:2022-11-03 02:11:27浏览次数:39  
标签:https xxx server nginx key 强制 listen

  • nginx 强制https

     

    通常有如下两种方法强制https
    推荐第二种,第二种更高效
    1、使用nginx的rewrite方法

    server {
                listen 80;
                server_name  xxx.com;
                rewrite ^(.*)$   https://$host$1 permanent;
    }
    

    2、使用nginx的301状态码

    server {
                listen 80;
                listen 443;
                server_name xxx.com;
                ssl   on;
                ssl_certificate    /data/www-key/xxx.pem;
                ssl_certificate_key    /data/www-key/xxx.key;
                if ($scheme = http) {
                return 301 https://$server_name$request_uri;
                }
    
    }

标签:https,xxx,server,nginx,key,强制,listen
From: https://www.cnblogs.com/yelanggu/p/16853126.html

相关文章