nginx配置https

时间:2022-07-23
本文章向大家介绍nginx配置https,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

只配置443会导致http和https共存, 只要再80里配置个重定向即可return 301 https://$server_name;

server {    
        listen      80;
        server_name www.zzes1314.cn;

        return 301 https://$server_name;
        location / {
            root html/mainPage;
            index index.html index.htm;
        }
    }

    # HTTPS server
    #
    server {
       listen       443 ssl;
       server_name  www.zzes1314.cn;
       ssl on;
       ssl_certificate      1_www.zzes1314.cn_bundle.crt;
       ssl_certificate_key  2_www.zzes1314.cn.key;

       ssl_session_cache    shared:SSL:1m;
       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 / {
           root html/mainPage;
           index index.html index.htm;
       }
    }

配置http2

./configure  --with-http_v2_module
make
make install

nginx.conf中 就在https配置后加个http2即可

    server {
       listen       443 ssl http2;