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

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



Solution 1:[1]

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)

Solution 2:[2]

I had the same issue on Ubuntu 16.04

I've just removed post and pre hooks in /etc/letsencrypt/renewal/*.conf and changed authenticator to nginx - I had in two entries standalone.

And it is working now fine.

Edit:

Recommended way to update renewal config is to reissue new certificate using:

certbot -i nginx -d example.com -d www.example.com certonly

Solution 3:[3]

I had the same error...

When I installed certbot, I followed the instructions and put in a cronjob (5 3 15 * *):

certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"

this morning nginx was dead, and the log showed

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

I did not connect the two, but do I understand that certbot triggers the nginx failure?

Solution 4:[4]

You can run this command line before run reload nginx.

sudo nginx -c /etc/nginx/nginx.conf

or

sudo nginx -c /usr/local/etc/nginx/nginx.conf

then you can start nginx nomaly

sudo nginx -s reload

Good luck.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hotenov
Solution 2 S.S. Anne
Solution 3 Wido Menhardt
Solution 4 tuanngocptn