Report this

What is the reason for this report?

Nginx define logs in nginx.conf vs. server blocks

Posted on September 7, 2014
igor

By igor

If I enable access and error logs in /etc/nginx/nginx.conf:

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

Should I also be keeping logs in server blocks like:

server {
    listen 80;
    server_name www.somesite.org;
    root /var/www/somesite/;
    access_log /var/log/nginx/somesite.org.access.log;
    error_log /var/log/nginx/somesite.org.error.log;
}

Or this is redundant assuming that everything that’s in “somesite” specific logs is already captured by master logs defined in nginx.conf?

I do have several virtual hosts though and I am wondering if above is true, would it be a better practice to disable logging in nginx.conf and log in individual server blocks so that I can keep domain name specific logs nice and clean?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

If you have several virtual hosts, it’s generally good practice to separate the log files by defining site specific logs in your server block. Though it’s really just a matter of preference and readability. So it’s up to you.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.