エラー 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 から削除する方法を説明しました。 古いドメインの証明書を削除します(証明書を暗号化しましょう)。
サーバー上でまだホストされているアクティブなドメインの SSL 証明書をコマンドで削除する場合: sudo certbot delete、証明書は自動的に削除されますが、サービスが再起動されるまでセッション内ではアクティブなままになります。 nginx。 nginx -t コマンド (サービスのテスト) を使用すると、上記のエラーでテストが失敗することに驚くかもしれません。ただし、解決策は非常に簡単です。

nginx を修正: [emerg] が証明書 fullchain.pem をロードできない
SSL証明書をインストールする場合 Let’s Encrypt Certbot を介して、ドメインの nginx の設定ファイルに、証明書の存在を示す数行が追加されます。証明書が削除されると、その行は nginx config に残るため、手動で削除する必要があります。つまり、以下の行です。
.....
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
SSL 証明書を削除したドメインの nginx config ファイルからこれらの行を削除した後、次のコマンドを実行します。 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。