yum -y install epel-release
yum -y install certbot
certbot certonly --standalone -d ajanuw.fun // 如果https到期,只需关闭nginx,再次执行此命令即可续订
// 填写邮箱 [email protected]
// 同意条款 A
// 是否愿意与Electronic Frontier分享您的电子邮件地址 Y
cp -r /etc/letsencrypt/ ./ 复制一份
tar czf letsencrypt.tar.gz letsencrypt/ 压缩一个
// vi nginx.conf 修改配置文件
// Docs: https://mozilla.github.io/server-side-tls/ssl-config-generator/
设置自动续订:
echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew" | sudo tee -a /etc/crontab > /dev/null
nginx.conf
server {
# listen 80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.ajanuw.fun;
ssl_certificate /etc/letsencrypt/live/ajanuw.fun/cer.pem; #
ssl_certificate_key /etc/letsencrypt/live/ajanuw.fun/privkey.pem; #
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
下面是我最新的配置
- nginx version: nginx/1.17.3
- OpenSSL 1.0.2k-fips 26 Jan 2017
- 我的域名 ajanuw.xyz
- 先查看下使用certbot生成的密匙
# ls /etc/letsencrypt/live/ajanuw.xyz/
cert.pem chain.pem dhparam.pem fullchain.pem privkey.pem README
这个dhparam.pem
是我在生成密匙后新添加的 curl https://ssl-config.mozilla.org/ffdhe2048.txt > ./dhparam.pem
- 配置nginx.conf
server {
listen 80;
listen [::]:80;
server_name www.ajanuw.xyz;
# redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://www.ajanuw.xyz;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/ajanuw.xyz/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/ajanuw.xyz/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_dhparam /etc/letsencrypt/live/ajanuw.xyz/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
add_header Strict-Transport-Security "max-age=63072000" always;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/ajanuw.xyz/fullchain.pem;
// 填写你服务器的ip
resolver 127.0.0.1;
location / {
root html;
index index.html index.htm;
# proxy_pass http://127.0.0.1:3000;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}