开启 SSL 的基本配置
关闭80
端口,
打开443
,
打开ssl on
,
配置ssl的路径
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl on;
ssl_certificate /etc/nginx/ssl/phpjit.net.crt;
ssl_certificate_key /etc/nginx/ssl/phpjit.net.key;
重启nginx
service nginx restart 或者reload
重启之前可以检测nginx配置是否成功
nginx -t
http 跳转到 https:
多加一个 server block,监听 80 端口,返回 301 重定向。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name laravist.com www.laravist.com;
return 301 https://$server_name$request_uri;
}
加强配置
https
生成一个 DH group。
sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
再来就是针对 SSL 做一些自定义的设置:
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
还有一种简洁的方式
如何免费的让网站启用HTTPS
let’s Encrypt 安装
报错处理
Problem binding to port 80: Could not bind to IPv4 or IPv6.
则原因是 nginx 占用了80端口,输入 service nginx stop。然后再次执行证书安装命令,即可顺利安装。
安装完毕后,输入 service nginx start,重启 nginx 服务。