8

I have an nginx acting as a proxy in front of of a backend and I want to separate the requests made to a specific location to a separate file.

Still the requests should go to the same backend server but I don't want to see them inside the main access log.

Also I don't want to specify all the proxy_ stuff twice.

server {
    ...
    access_log  /var/log/nginx/jira.access.log full;
    error_log  /var/log/nginx/jira.error.log;
    client_max_body_size 150m;        

    location /special/ {
        }

    location / {

            # many lines of config params for proxy_...
            proxy_pass   http://dowa-02.example.com:8080;
            ...
    }
}
6

UPD

Hmmm... access_log directive have a "feature".

Requests are logged in a context of a location where processing ends. This may be different from the original location, if an internal redirect happens during request processing.

In case of try_files the internal redirect. Try change try_files to include & remove named location.

END OF UPD


In order not to repeat many times "proxy_ stuff", you can use include directive, for example. But try_files and named location are much better :)

server {
    ...
    access_log  /var/log/nginx/jira.access.log full;
    error_log  /var/log/nginx/jira.error.log;
    client_max_body_size 150m;

    location /special/ {
        try_files $uri @backend;
        access_log /var/log/nginx/special.access.log full;
    }

    location / {
        try_files $uri @backend;
    }

    location @backend {
            # many lines of config params for proxy_...
            proxy_pass   http://dowa-02.example.com:8080;
            ...
    }
}
5
  • thanks, I was considering the same approach, implemented it did service nginx reload, nothing changed, did nginx restart nothing changed... the special log file is not created and the log is still full of /special/ requests... – sorin Apr 12 '13 at 16:59
  • Something very strange was happening with nginx, i needed to install it again as to make it work. Until I stopped it any command was "succesful" but in fact was doing nothing. – sorin Apr 12 '13 at 17:29
  • see update, please – cadmi Apr 12 '13 at 17:30
  • Now the question is which is the final context? I would really like to used named locations as they seem to be the right way to keep the configuration easy to maintain. Now: nginx is creating the logs but it always using the access log which is specified at server level. Any workarounds without include? – sorin Apr 12 '13 at 17:43
  • 1
    only include is workaround. final context in original location instead of named - a feature of access_log directive. – cadmi Apr 13 '13 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.