一、配置pem证书

1、申请https证书,绑定域名信息

2、配置nginx

打开nginx.conf配置文件,写入以下代码

server {
 
        listen                          443 ssl;


        server_name                   域名;
 
        ssl_certificate                  pem证书本地地址;
 
        ssl_certificate_key              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 / {
            index  index.html index.htm;
            
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass 转发的内网加端口;
        }
 
    }

二、将 http 重定向 https

server {
    listen 80;
    server_name somnus.test.com;
    #将请求转成https
    rewrite ^(.*)$ https://$host$1 permanent;
}

更多推荐