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.
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.
sudo nginx -c /usr/local/etc/nginx/nginx.conf # -c stands configuration file.
- Reload nginx:
nginx -s reload
Second solution is to change the path of nginx.pid in the configuration file.
- Open the Nginx config file using the below command.
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)
# 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.
sudo nginx -c /usr/local/etc/nginx/nginx.conf nginx -s reload
I hope this helps you to resolve your Nginx issue.
Visit https://techtalkbook.com to find more related topics.