There are multiple nginx conf in my system and I want to debug where nginx is forwading the request for debugging purpose.
I wanted see in the nginx log with the proxy_pass value
location /api/superadmin/ {
proxy_pass http://127.0.0.1:9039;
}
For example in the logs
119.82.108.182 - - [18/Dec/2023:09:06:37 +0000] "GET /api/superadmin/ HTTP/1.1" 200 52 "-" "PostmanRuntime/7.29.0" "-"
In the above log wanted to see proxy_pass
value as well for debugging. How to check this?
The log_format
and access_log
directives allow you to customise the access log or even generate multiple access logs for different purposes. See the log module.
Logging $server_name
and $server_port
will help identify which server { ... }
block handled the request, by showing the value of the server_name
and listen
directives within that block. Or -
if the server name is missing.
Logging $proxy_host
and $proxy_port
will help identify which proxy the request was forwarded to using proxy_pass
. Or -
if the request was handled differently.
For example, the following statements placed in the http
block, will append the above information to test.log
, for requests to any server
block:
log_format test '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$server_name:$server_port" "$proxy_host:$proxy_port"';
access_log /var/log/nginx/test.log test;
Change the access_log
logfile path to match the one used by your OS.