本文主要是介绍Nginx服务器安装证书并启用SSL(acme.sh),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前提
- 您已购置vps服务器,例如阿里云全球站ecs、AWS EC2、Azure VM、GCP Compute等
- 安全组已开启80、443端口,且访问源设置为0.0.0.0/0
- 域名已设置A记录指向当前操作服务器,若您使用aws ec2,有公有 IPv4 DNS,可供使用
安装Acme.sh并申请证书Step-By-Step
Ubuntu—EasyWay
cat >> install-CA.sh << EOF
#!/bin/bash
rm -rf /etc/nginx/cert/ && mkdir /etc/nginx/cert/
read -p "Enter your domain: " domain
rootDomain=\`echo $domain|cut -d '.' -f2-\`
apt -y install wget unzip socat
curl https://get.acme.sh | sh
rm -rf /usr/local/bin/acme.sh
ln -s /root/.acme.sh/acme.sh /usr/local/bin/acme.sh
acme.sh --register-account -m admin@$rootDomain
acme.sh --issue -d ${domain} --standalone -k ec-256
cp /root/.acme.sh/${domain}_ecc/fullchain.cer /etc/nginx/cert/server.cert
cp /root/.acme.sh/${domain}_ecc/${domain}.key /etc/nginx/cert/server.key
acme.sh --installcert -d ${domain} --ecc --key-file /etc/nginx/cert/server.key --fullchain-file /etc/nginx/cert/server.cert
systemctl start nginx
EOF
CentOS—EasyWay
cat >> install-CA.sh << EOF
#!/bin/bash
rm -rf /etc/nginx/cert/ && mkdir /etc/nginx/cert/
read -p "Enter your domain: " domain
rootDomain=\`echo $domain|cut -d '.' -f2-\`
yum -y install wget unzip socat
curl https://get.acme.sh | sh
rm -rf /usr/bin/acme.sh
ln -s /root/.acme.sh/acme.sh /usr/bin/acme.sh
acme.sh --register-account -m admin@$rootDomain
acme.sh --issue -d ${domain} --standalone -k ec-256
cp /root/.acme.sh/${domain}_ecc/fullchain.cer /etc/nginx/cert/server.cert
cp /root/.acme.sh/${domain}_ecc/${domain}.key /etc/nginx/cert/server.key
acme.sh --installcert -d ${domain} --ecc --key-file /etc/nginx/cert/server.key --fullchain-file /etc/nginx/cert/server.cert
systemctl start nginx
EOF
nginx配置设置—以centos为例
修改nginx.conf的内容
取消Settings for a TLS enabled server下的注释内容
server {listen 443 ssl http2;listen [::]:443 ssl http2;server_name YourDomain;root /usr/share/nginx/html;ssl_certificate "/etc/nginx/cert/server.cert";ssl_certificate_key "/etc/nginx/cert/server.key";ssl_session_cache shared:SSL:1m;ssl_session_timeout 10m;ssl_ciphers DEFAULT;# This is default SSL_ciphers setting,if you get error,you can change it like me,set DEFAULT#ssl_ciphers PROFILE=SYSTEM;ssl_prefer_server_ciphers on; # Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;error_page 404 /404.html;location = /40x.html {} error_page 500 502 503 504 /50x.html;location = /50x.html {} }
Trouble Shooting
SSL_CTX_set_cipher_list:no cipher match
报错信息
[emerg] 11926#11926: SSL_CTX_set_cipher_list("PROFILE=SYSTEM") failed (SSL: error:1410D0B9:SSL routines:SSL_CTX_set_cipher_list:no cipher match)
Solution
将nginx.config默认的ssl_ciphers PROFILE=SYSTEM;设置为ssl_ciphers DEFAULT;
重启nginx即可
这篇关于Nginx服务器安装证书并启用SSL(acme.sh)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!