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

Sandeep Agrawal
2 min readAug 16, 2020
  • 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

The first solution is to run commands to generate the 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

Solution 2

The 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

References:

Hope this helps resolve your nginx issue.

Originally published at https://techtalkbook.com on August 16, 2020.

--

--