Certbot renew: nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)

Roshan Shrestha picture Roshan Shrestha · Mar 30, 2018 · Viewed 13.7k times · Source

Certbot and nginx versions:

certbot installed using certbot.eff.org install guide.

  • Certbot version: 0.22.2
  • Nginx version: 1.10.3

Getting ssl certificates works fine:

certbot --nginx

But, in renewal of cerbot certificated

certbot renew --dry-run

nginx fails to start causing:

nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)

I have tried changing post-hook and pre-hook in /etc/letsencrypt/renewal/*com.conf/

  • commenting installer=nginx
  • changing authenticator to nginx and standalone

Adding post and pre hooks in /etc/letsencrypt/renewal-hooks/pre/ and /etc/lestencrypt/renewal-hooks/post/ to stop and start nginx service.

Seems nginx is not starting properly or isn't stop properly. after renewal completes nginx fails with (code=exited, status=1/FAILURE)

Nginx error log show:

nginx log image

Error while certbot renew: Certbot error log in renewal

Answer

hotenov picture hotenov · Nov 23, 2019

Try to execute:

sudo service nginx restart

Then test your nginx configuration file(s) (until you see "nginx: configuration file /etc/nginx/nginx.conf test is successful")

sudo nginx -s reload -t

Pay attention on paths to certificates, and other stuff

and then reload configuration without -t option:

sudo nginx -s reload

It's not recommended to modify configuration files in /etc/letsencrypt/ but creating (if it doesn't exist) and modifying cli.ini file here is working for me. You can specify post-hook in this file once and it will work for all your certificates, see my current file:

# /etc/letsencrypt/cli.ini
max-log-backups = 0
authenticator = webroot
webroot-path = /var/www/html
post-hook = service nginx reload
text = True

I hope this will help future readers. Solution source is here (however the article is in Russian)