ข้อผิดพลาด 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: [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 confg ของโดเมนที่คุณลบใบรับรองออก 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.