6

I noticed when I test my nginx config using nginx -t, it gives me a warning:

nginx: [alert] could not open error log file: open() "/var/logs/nginx/error.log" failed (2: No such file or directory)

Which makes sense, since the log path for nginx is actually set up to be /var/log/nginx/ not /var/logs/nginx.

I scanned the entire nginx config directory and there is nothing there referencing /var/logs. I'm at a loss as to where this log location could be written?

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Brian
  • 7,204
  • 12
  • 51
  • 84
  • There isn't `/var/logs` path, maybe your nginx config file have a mistake in logging path. True path for logs is `/var/log/nginx/*.log`. – Benyamin Jafari May 29 '18 at 06:19

3 Answers3

11

Run this command in a terminal (note: capital V):

nginx -V

Do you find /var/logs there? Your nginx might be compiled with that default file location.

[EDIT]

I guess that some of your server blocks don't have the "error_log" directive. So nginx tries the default one for them. Note that by default the error_log is always on.

To fix this issue, you can add this line on the main block (the top level) such that all child blocks can inherit the setting:

error_log /var/log/nginx/error.log;
Chuan Ma
  • 9,754
  • 2
  • 45
  • 37
8

You can create these missed files:

cd /var/log/nginx/
sudo touch error.log
sudo touch access.log
sudo chmod 750 *.log

Then trigger nginx service:

sudo systemctl daemon-relod
sudo service nginx restart 

[NOTE]:

You can also disable nginx logging:

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
2

You have a bad compiled default. Anything nginx notices before loading the config goes to the path for the error log defined at compile time. Recompile nginx with sane path or symlink log to logs if you can't.