官方说的很详细。
这里就以本站域名为例,说下配置过程。当前域名 DNS 托管到 CloudFlare ,所以变量是 CF 开头。如果是 Godaday 是不一样的,注意区分。
# Godaday # export GD_Key="key" # export GD_Secret="secret" # --dns dns_gd # CloudFlare export CF_KEY="key" export CF_Email="email" # --dns dns_cf # Aliyun # First you need to login to your Aliyun account to get your RAM API key. https://ram.console.aliyun.com/users,并授予权限 # export Ali_Key="key" # export Ali_Secret="email" # --dns dns_ali # 生成证书 ~/.acme.sh/acme.sh --issue -d xingbaifang.com -d *.xingbaifang.com --dns dns_cf # 安装证书 ~/.acme.sh/acme.sh --installcert -d xingbaifang.com -d *.xingbaifang.com \ --key-file /etc/nginx/ssl/xingbaifang.com.key \ --fullchain-file /etc/nginx/ssl/xingbaifang.com.fullchain.cer
复制
生成证书后,需要记录证书路径,然后修改 Nginx 配置。
一般 Nginx 安装目录在 /etc/nginx 中,先修改 nginx.conf ,添加 SSL 共有配置,这样每一个域名都避免重复添加,域名中,只配置证书路径。
# nginx.conf # 在 http 节点中配置 SSL 共有路径 ssl common config ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; ssl_protocols TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE'; ssl_prefer_server_ciphers on; add_header Strict-Transport-Securit max-age=15768000; ssl_stapling on; ssl_stapling_verify on;
复制
然后在具体域名配置文件中,配置证书路径,比如我的域名配置文件在 /etc/nginx/conf.d/ 目录中
# xingbaifang.com.conf server { listen 80; server_name xingbaifang.com www.xingbaifang.com; return 301 https://$host$request_uri; } server { listen 12443 ssl http2; server_name xingbaifang.com www.xingbaifang.com; ssl_certificate /etc/nginx/ssl/xingbaifang.com.fullchain.cer; ssl_certificate_key /etc/nginx/ssl/xingbaifang.com.key; location / { proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; proxy_buffering off; proxy_pass http://127.0.0.1:3000; } client_max_body_size 50m; }
复制
然后重启 nginx