Nginx: Get the upstream URI used by proxy_pass

Viewed 3574

I am using proxy_pass and would like to log the URI used by proxy_pass.

I can log every detail like $upstream_addr (IP) of the process except the URI itself.

Am I missing something or this is not possible?

2 Answers

I believe the variable you would want to use is $proxy_host in the logging format.

Nginx Var Reference

$proxy_host name and port of a proxied server as specified in the proxy_pass directive

I am using proxy_pass and would like to log the URI used by proxy_pass.

There's $upstream_addr but you still can't get full URI there.

It depends but if your app is already in production, add $upstream_addr and check your upstream's access log.

If your app is still in debugging, use nginx's debug level in error_log directive.

I was hoping to get the full URI since I had a little trouble with my params. Something they seem to be ignored and I tried to log these.

Well, you probably hit by nginx's proxy_pass URI processing rule.

A request URI is passed to the server as follows:

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

   location /name/ {
       proxy_pass http://127.0.0.1/remote/;
   }

If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:

   location /some/path/ {
       proxy_pass http://127.0.0.1;
   }

If you need to pass full URI to your upstream, just specify your upstream rather than an upstream URI to your proxy_pass, and remove any trailing forward slashes there.

proxy_pass http://backend_upstream;
Related