nginx 添加htttps服务器

 

注意:server_name 多个域名时用空格隔开,否则可能报“could not build server_names_hash, you should increase server_names_hash_bucket_size”(两个域名使用443端口时)

server {
    listen    80;
    server_name www.xxx.com;
    rewrite ^(.*) https://$server_name$1 permanent; # 这里重定向到https
}

    server {
    listen       443 ssl;
       server_name  www.xxx.com xxx.com;
    ssl on;   #设置为on启用SSL功能。
       ssl_certificate      C:/xxx/www.xxx.com.pem;
       ssl_certificate_key  C:/xxx/www.xxx.com.key;

       ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;#使用此加密套件。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
    ssl_prefer_server_ciphers on;

        location / {
            proxy_pass http://localhost:8080;            
        }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
           proxy_pass http://localhost:8080;
        }

        location ~ .*\.(js|css)?$
        {
            proxy_pass http://localhost:8080;
        }

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

 

实战配置:

server {
    listen    80;
    server_name auth.xxxx.com;
    rewrite ^(.*) https://$server_name$1 permanent; # 这里重定向到https
}

server {
    listen       443 ssl;
    server_name  auth.xxxx.com;
    ssl on;   #设置为on启用SSL功能。
    ssl_certificate      C:/.../ssl/7837917_auth.xxxx.com.pem;
    ssl_certificate_key  C:/.../ssl/7837917_auth.xxxx.com.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;#使用此加密套件。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
    ssl_prefer_server_ciphers on;
    location / {
        proxy_pass http://localhost:8080;
    }
}

 

posted @ 2022-04-04 09:52  三瑞  阅读(207)  评论(0编辑  收藏  举报