How can I separate access logs from requests of two different domains of the same server?

Satoru.Logic asked:

My nginx configuration looks like this:

server {
   listen 80;

   access_log /var/log/myapp/nginx/access.log;


Currently requests from both domains are logged into the same file, I want to separate these so that requests from continue to be saved in access.log, while requests from be saved in domain2.access.log.

How can I do this?

My answer:

You can use a variable in your access_log entry. For instance:

access_log /var/log/nginx/$http_host-access.log

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.