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端口

猜你喜欢

转载自www.cnblogs.com/lesten/p/10106151.html