Ngnix SSL配置(HTTP、HTTPS兼容)

一、使用阿里云提供证书

下载aliyun证书for Nginx,解压出两个文件,.pem和.key文件

在nginx安装目录Conf文件夹下新建cert文件夹,拷贝两个密钥文件

二、配置nginx

打开nginx安装目录下conf目录中的ngnix.conf,修改server

server {
    listen 443;
    server_name localhost;
    ssl on;
    root html;
    index index.html index.htm;
    ssl_certificate   cert/213980337690246.pem;
    ssl_certificate_key  cert/213980337690246.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 / {
        root html;
        index index.html index.htm;
    }
}

现在网站已经支持HTTPS访问

如果想要同时支持http访问
添加监听80口:listen 80;
ssl on可以注释掉
原文地址:https://www.cnblogs.com/rainbowz/p/7410536.html