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?
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?
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;
I believe the variable you would want to use is $proxy_host
in the logging format.
$proxy_host
name and port of a proxied server as specified in the proxy_pass directive
$proxy_host
is just the domain name. 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. It seems that there isn't any $proxy_request_uri
function I could use since it's usual the same as the original one. β
Amarelle In my first NGINX configurations I struggled with getting a lot of 404 errors from the upstream servers when I believed I should be passing a good URI. I could log the uri my NGINX server received, but was never sure what my NGINX server was passing to the upstream server. In my experience and research I never found a way to log what NGINX passes on the NGINX server that is handling the client request.
BUT, the upstream server knows the complete URI the NGINX server is requesting. In my case the upstream server was handled by another team and I did not have access to the logs on that server. Finally I realized, why not use my own upstream server where I do have access to the logs as well as one I can specify how it logs. I could easily do this because I had more than one NGINX server is my development environmennt. I use the first NGINX server as the proxy server I am configuring, and the second as the upstream server.
I will call the original NGINX server I am configuring "MyProxyServer.com" I will call the upstream server I am using to log the URI that MyProxyServer.com passes "Upstream.com"
On MyProxyServer.com I configured :
location /upstream/ {
access_log /etc/nginx/logs/received_requests.log logformat1;
proxy_pass https://Upstream.com/;
}
On Upstream.com I configured :
location / {
access_log /etc/nginx/logs/unexpected_uri.log logformat1;
try_files /unexpected.html =123;
}
location /uricapture/ {
access_log /etc/nginx/logs/uri_passed.log logformat1;
try_files /index.html =234;
}
Using your favorite client, GET https://MyProxyServer.com/uricapture/the/final/endpoint/
On MyProxyServer.com I can examine the log and see that it received a GET request. GET /uricapture/the/final/endpoint/
On Upstream.com I can examine the log, and in the uri_passed.log I see that MyProxyServer.com requested: GET /the/final/endpoint/
I got back the index.html file I had set up.
© 2022 - 2024 β McMap. All rights reserved.