Question

Nginx define logs in nginx.conf vs. server blocks

  • Posted on September 7, 2014
  • igorAsked 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?


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

This comment has been deleted