第一步、安裝snapd
安裝
sudo yum install epel-release snapd -y
sudo systemctl enable --now snapd.socket
設(shè)置軟鏈接將源文件(/var/lib/snapd/snap)軟鏈接到目標(biāo)文件(/snap)
sudo ln -s /var/lib/snapd/snap /snap
第二步口柳、刪除舊的Certbot(如果初次安裝竹勉,則跳過這步)
sudo apt-get remove certbot
或
sudo dnf remove certbot
或
sudo yum remove certbot.
第三步剧包、通過 snapd 安裝 Certbot
安裝
sudo snap install --classic certbot
添加軟鏈接
sudo ln -s /snap/bin/certbot /usr/bin/certbot
第四步、添加 SSL 證書(大部分錯(cuò)誤會(huì)發(fā)生在這一步)
1滑燃、指定Nginx目錄
sudo certbot --nginx --nginx-server-root=/usr/local/nginx/conf
執(zhí)行后可能遇到錯(cuò)誤:
Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",)
一般是由于沒有將nginx放到環(huán)境變量中
解決方法:設(shè)置nginx軟連接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
ln -s /usr/local/nginx/conf/ /etc/nginx
設(shè)置完后重新執(zhí)行
sudo certbot --nginx --nginx-server-root=/usr/local/nginx/conf
可能會(huì)遇到錯(cuò)誤:
Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('Nginx build is missing SSL module (--with-http_ssl_module).',)
發(fā)現(xiàn)是沒有安裝ssl模板導(dǎo)致的
找到nginx文件夾下執(zhí)行:
./configure --with-http_ssl_module
make && make install
解決后重新執(zhí)行:
sudo certbot --nginx --nginx-server-root=/usr/local/nginx/conf
出現(xiàn)以下輸入郵箱的提示役听,表示上述問題解決
接著按照提示輸入
可以看到最后雖然證書申請(qǐng)成功,但是并沒有安裝成功表窘,根據(jù)提示“server_name”沒設(shè)置好典予,找到nginx配置文件nginx.conf,將此處原本的location改為想要配置的域名
保存后reload一下nginx配置:
/usr/local/nginx/sbin/nginx -s reload
然后重新執(zhí)行一下乐严,就可以看到證書安裝成功:
生成的證書默認(rèn)會(huì)出現(xiàn)在/etc/letsencrypt/live文件夾下
第五步瘤袖、生成DH密鑰交換協(xié)議
openssl dhparam -out /etc/ssl/certs/dhparams.pem 2048
第六步、nginx配置https
進(jìn)入nginx.conf可以看到有https server的注釋
按照注釋配置即可:
server {
listen 443 ssl;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
ssl_certificate /etc/letsencrypt/live/www.linkk.top/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.linkk.top/privkey.pem;
ssl_dhparam /etc/ssl/certs/dhparams.pem;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
}
保存后重啟nginx(注意這里不是reload)
# 停止
nginx -s stop
# 啟動(dòng)
nginx
重啟后https若無法訪問可以檢查一下云服務(wù)器的安全組配置443端口入方向是否開啟