将网站协议从 HTTP 升级为 HTTPS (基于 Nginx 配置)

想写一大堆的,但是发现网上都有,
我就把我的配置文件放这里贴一下.

我的 Nginx 配置文件

server {
    listen 443;
    server_name inick.top;
    ssl on;
    root /home/git/web/my-site;
    index index.html;
    ssl_certificate /etc/nginx/cert/1963213_inick.top.pem;
    ssl_certificate_key /etc/nginx/cert/1963213_inick.top.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 /home/git/web/my-site;
        index index.html;
    }
}

server {
    listen 80;
    server_name inick.top www.inick.top;
    rewrite ^/(.*)$ https://$host$1 permanent;
}


证书文件需要自己去申请.
配置完之后,记得重启 Nginx ,开放服务器 443 端口.

这样子我的两个域名都可以访问

https://www.inick.top
https://inick.top

-- iNick
-- 2019/05/07

你可能感兴趣的:(将网站协议从 HTTP 升级为 HTTPS (基于 Nginx 配置))