Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

When nginx start, it creates a log file "access.log" with 0 size. But no log is written in it. error.log works fine.

nginx.conf:

http {

    access_log /usr/local/webserver/nginx/logs/access.log combined;

    ....

}

The logs file is:

-rw-r--r--  1 root root   0 Mar 4 00:54 access.log

-rw-r--r--  1 root root 3903 Mar  4 00:54 error.log

I am totally confused.

Is it a permission issue?

However, in the later part of nginx.conf, in the server {} section, the access_log works! Why HTTP {} section not working?

1 Answer

0 votes
by (44.4k points)

Depending on your configuration, nginx master process and worker processes possibly run as completely different users.

To see users and groups for nginx processes:

ps -eo "%U %G %a" | grep nginx

root root nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

www-data www-data nginx: worker process

The worker process user wants to write permission for the log file.

To see file permissions of access.log:

ls -l /var/log/nginx/access.log

-rw-r----- 1 www-data www-data 0 Apr 29  2012 /var/log/nginx/access.log

In this case, the access log is owned by the nginx worker process and has to write access.

See also nginx http_log_module docs.

As a secondary issue, nginx logs is also rotated once they reach a particular size by the logrotate cronjob. When the new log file is created, it should be created with owner, group and permissions to permit the nginx worker process to write to that.

These log rotation settings for nginx are outlined in /etc/logrotate.d/nginx

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
asked Dec 8, 2020 in AWS by devin (5.6k points)

Browse Categories

...