D
D
Daniel Newman2013-01-20 15:27:52
Nginx
Daniel Newman, 2013-01-20 15:27:52

How to cut nginx logs by $host-access.log files?

There is a proxying nginx in front of the virtual machines, I want to cut the logs by domains into the $host-access.log files of the same name with nginx initially, but something doesn’t work like a stone flower.

http {

upstream first-upstream {
    server 12.34.56.1:80;
}

#access_log  /var/log/nginx/$host-access.log;

server {
    listen        80 default_server;

    location / {
        proxy_pass  http://first-upstream;
        #access_log  /var/log/nginx/$host-access.log;
}

Doesn't work anywhere including a line access_log. Falls into error.log:
...testing "/etc/nginx//html" existence failed (2: No such file or directory) while logging request...

Sysoev solved this issue in some strange way, but I do not have root, but bunches of upstreams of different IPs.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim, 2013-01-20
@danielnewman

So describe root, it is written quite specifically. It is clear that you do not need it, but it is needed for logging to work =)

S
Sergey Petrikov, 2013-01-20
@RicoX

server {
server_name localhost.com;
# Folder with site content (handy when it matches the domain name)
root /var/www/localhost;
# Setting up logs, each virtual domain has its own log
access_log /var/log/nginx/localhost.com-access.log;
error_log /var/log/nginx/localhost.com-error.log;
I recently wrote a note here, look there it is habrahabr.ru/post/164401/

V
VBart, 2013-01-21
@VBart

I'll just quote the documentation that no one reads anyway:

Variables can be used in the file path (0.7.6+), but such logs have some limitations:
[...]
  • at each entry in the log, the existence of the root directory for the request is checked - if this directory does not exist, then the log is not created. Therefore, root and access_log must be described at the same level:
        server {
            root       /spool/vhost/data/$host;
            access_log /spool/vhost/logs/$host;
            ...
    

@ nginx.org/r/access_log/ru

V
Viktor Taran, 2014-02-07
@shambler81

Do not forget that access logs in nginx are not needed because they duplicate Apache, and you don’t need static that worked validly.
But it will add load to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question