nginx http自动跳转https

小七夕 1年前 ⋅ 12187 阅读

 

server {                                #第一个server块,用于监听80端口               
        listen       80;
        server_name  localhost;

        location  /{
            root   html;
            index  index.html index.htm;
            rewrite ^(.*)$  https://$host$1 permanent;     #先把这一行注释掉,分别用80端口和443端口访问本机,若是都可以正常访问,添加上这一行即可!
        }

    }

    server {                               #第二个server块,用于监听443端口
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      cert/server.pem;       #证书的位置是相对于当前配置文件所在的位置的!
        ssl_certificate_key  cert/server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

 


注意:本文归作者所有,未经作者允许,不得转载