Skip to content
Home » nginx: [error] open() ‘/usr/local/var/run/nginx.pid’ failed (2: No such file or directory)

nginx: [error] open() ‘/usr/local/var/run/nginx.pid’ failed (2: No such file or directory)

Nginx

About the error

  • What is the Error:
    nginx [error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)
  • Why is this Error:
    This error occurs if there is no nginx directory or no nginx.pid file found in the system.
  • Reason for this Error:
    The reason is that every time you reboot the system, nginx.pid gets deleted automatically.

Solution 1

First solution is to run command to generate missing file nginx.pid.

  • Provide a specific config file path to Nginx command so that nginx.pid will be created if the file is not present.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo nginx -c /usr/local/etc/nginx/nginx.conf
# -c stands configuration file.
sudo nginx -c /usr/local/etc/nginx/nginx.conf # -c stands configuration file.
sudo nginx -c /usr/local/etc/nginx/nginx.conf
# -c stands configuration file.
  • Reload nginx:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
nginx -s reload
nginx -s reload
nginx -s reload

Solution 2

Second solution is to change the path of nginx.pid in the configuration file.

  • Open the Nginx config file using the below command.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo vim /usr/local/etc/nginx/nginx.conf
sudo vim /usr/local/etc/nginx/nginx.conf
sudo vim /usr/local/etc/nginx/nginx.conf
  • Search for “nginx.pid;” and you should find it as commented code like below so just uncomment that line and save the file. (You can change the location from ‘/logs’ to something else as if you want)
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# pid logs/nginx.pid; // remove # to uncomment this line.
# pid logs/nginx.pid; // remove # to uncomment this line.
# pid logs/nginx.pid; // remove # to uncomment this line.
  • Run the same two commands as mentioned in the above ‘solution 1’ section to load the config file and start Nginx.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo nginx -c /usr/local/etc/nginx/nginx.conf
nginx -s reload
sudo nginx -c /usr/local/etc/nginx/nginx.conf nginx -s reload
sudo nginx -c /usr/local/etc/nginx/nginx.conf
nginx -s reload

I hope this helps you to resolve your Nginx issue.


References


Related Posts

Visit https://techtalkbook.com to find more related topics.

Happy Coding!!!


Leave a Reply

Your email address will not be published. Required fields are marked *