0

I deleted my NGINX log because it was very large, thinking that NGINX would automatically create a new one in its place. It didn't, and now I don't have logs. The file was previously located at /opt/nginx/logs/error.log. I tried creating a new file with the same permissions in the same location but it doesn't appear to have helped. I'm running nginx/1.4.7 on an ubuntu 12.10 server.

How do I get my logging back?

I've tried sudo service nginx restart and it says nginx: unrecognized service. I think this might be because I'm using NGINX with Phusion Passenger to serve a rails app and Passenger has changed a few things. For example, NGINX lives in /opt/nginx instead of init.d.

3
  • To be clear, you don't actually care about restoring the Nginx log... you just need a log file. A blank one. Correct?
    – Brad
    Commented Jul 4, 2015 at 4:54
  • correct, i'll update the question Commented Jul 4, 2015 at 14:56
  • Instead of deleting the files I suggest you simply empty them with > /opt/nginx/logs/error.log or echo "" > /opt/nginx/logs/error.log.
    – TCB13
    Commented Sep 22, 2023 at 15:12

1 Answer 1

2

Passenger author here.

Restarting Nginx would actually make the log file come back. It's just that you're not using the right method to restart Nginx, because your Nginx install was installed from source.

Init scripts, e.g. /etc/init.d/nginx and service nginx restart, are not provided by the default Nginx source code. Init scripts are actually extensions provided by the operating system's Nginx package. If you install Nginx from source, then you can't use init scripts to control Nginx anymore. Instead, you will use more generic operating system primitives to control Nginx, such as PID files and signals. Learn more at the Passenger documentation.

Restarting Nginx is to be done by sending signals to it and by starting it again through the Nginx command. For example:

sudo kill $(cat /opt/nginx/logs/nginx.pid)
sudo /opt/nginx/sbin/nginx

To learn more about restarting an Nginx that was installed from source, read this part of the Passenger documentation.

1
  • If to run nginx you use /opt/nginx directory, so sudo /opt/nginx/sbin/nginx -s quit is prefer because pid can be in different place, dependent on configuration
    – Anatoly
    Commented Jul 11, 2015 at 21:01

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