1. 程式人生 > >nginx支援https

nginx支援https

如題,主要有三個步驟

1、獲取並下載ssl證書後

 在阿里雲控制檯-產品與服務-雲解析DNS-SSL證書

2、上傳證書 並修改nginx配置檔案nginx.conf

server {
    listen 443;
    server_name xxx.com;
    ssl on;
    root /home/wwwroot/; 
    index index.html index.htm;  
    ssl_certificate  cert_path/xxxxx.pem;  // your cert name
    ssl_certificate_key cert_path/xxxx.key;// your cert key name
    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;
    }
}
server {
    listen 80;
    server_name xxx.com;
    rewrite ^(.*)$ https://$host$1 permanent;
}  

其中,只需要修改

    ssl_certificate  cert_path/xxxxx.pem;  // your cert name
    ssl_certificate_key cert_path/xxxx.key;// your cert key name

key 和 pem 相對路徑和名稱就可以了

修改完成後 用 nginx -t 測試配置檔案是否有錯誤

nginx -s reload 重新載入配置檔案 

3、新增 ecs 安全組規則

放443埠