Centos 为Nginx 搭建https
- Nginx 扩展模块
- certbot文档 看文档,文档是最新的
如果执行 "certbot --nginx" 自动配置失败了, 那么可以执行 "certbot certonly -d ajanuw.fun" 获取或更新证书,然后在你的nginx中导入证书
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;
}
}