nginx cannot load certificate 全鏈.pem – Certbot 固定

錯誤 nginx cannot load certificate path/fullchain.pem 刪除證書後測試NGINX服務時出現 Let’s Encrypt 產生於 Certbot.

在服務器中,錯誤顯示如下:

nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/example.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed

後台nginx報錯

在上一篇文章中,我展示瞭如何從 Certbot 過去託管在服務器上但當前不再活動的域。 刪除舊域 Certbot certificates (讓我們加密證書).

刪除證書時 SSL 對於仍然託管在服務器上的活動域,通過命令: sudo certbot delete,證書會自動刪除,但它在會話中保持活動狀態,直到服務重新啟動 nginx. 使用 nginx -t 命令(測試服務),您可能會驚訝地發現測試失敗並出現上述錯誤。 但是,解決方案非常簡單。

nginx cannot load certificate
nginx cannot load certificate

修復了 nginx:[emerg] 無法加載證書 fullchain.pem

安裝證書時 SSL Let’s Encrypt 由 Certbot,在域的nginx的配置文件中,添加幾行表示證書的存在。 刪除證書後,這些行保留在 nginx 配置中,必須手動刪除。 即,以下幾行:

.....    

    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name example.com www.example.com;
    listen 80;
    return 404; # managed by Certbot

從您刪除證書的域的 nginx 配置文件中刪除這些行後 SSL, 執行命令 nginx -t 檢查是否一切正常。

[root@server]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server]# 

現在您可以安全地重啟服務了 nginx.

對技術充滿熱情,我很高興寫 StealthSettings.com 自 2006 年起。我在作業系統方面擁有豐富的經驗: macOS, Windows 對 Linux,而且還包括程式語言和部落格平台(WordPress)和線上商店(WooCommerce、Magento、PrestaShop)。

如何 » Web託管 » nginx cannot load certificate 全鏈.pem – Certbot 固定
發表評論