After I removed the version 0.7.x which was delivered by the Debian standard packages, I installed the version 1.4.1 of nginx by source.

It is possible to start nginx with service nginx start and I see that nginx is reserving the port 80 when I do netstat.

netstat -apn | grep nginx output:

tcp      0    0  *             LISTEN    3115/nginx 

The problem is, when I do service nginx status or service nginx stop I get this message:

could not access PID file for nginx ... failed!

Who can I fix this? And how do I prevent getting this problem?

EDIT: solution

  1. remove nginx
  2. then go to the source and ./configure --pid-path=/var/run/nginx.pid
  3. make
  4. checkinstall make install
  • 1
    Your solution is working for me.you can post your solution as answer. – Bhargav Patel Dec 22 '17 at 10:43

Debian probably configured/patched nginx for their package to put the pid file someplace specific that it doesn't do by default. When you replaced it via something compiled from source, it doesn't match the expectations of the service infrastructure.

I'd look at what patches and configuration options were done by the debian folks and recompile your 1.4.x version with the options to put the pid file in the same place.

As to how to prevent this type of problem? Either do things via packages or compile from source but not both. Or be aware you will need to take extra care when doing so since things will break.

| improve this answer | |
  • i know what you mean, but i dont know who to do it, could you give me a brief explanation? – Harrys Kavan Oct 6 '13 at 18:52
  • When Debian (or Red Hat, Ubuntu, Slackware, etc.) packages up something, they change things to make it fit. By default most software will install in /usr/local, to keep from co-mingling with the vendor-supplied operating system files. Debian wants things to install in the base system places. So they configure it to do so. Nginx might put its pid file in a place like /usr/local/var/run/nginx.pid, or somewhere in /var that is different from where Debian wants all pid files. So Debian changes nginx's configuration to do that. When you compile from source, you don't do that, and it breaks. – kurtm Oct 6 '13 at 18:59
  • nice! recompiled with --pid-path=/var/run/nginx.pid and now it works! – Harrys Kavan Oct 6 '13 at 19:07
  • 1
    @derty Also, keep in mind that if Debian does a security update of nginx, it will overwrite your source install. You should look into putting a hold on that package so your nginx install doesn't suddenly revert to an older version at some point. – kurtm Oct 6 '13 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.