nginx log full proxy_pass to log

Ale*_*man 8 nginx logging

Given the following location with proxy_pass, I want to log the fully qualified uri.

location ~* ^/?(foo/?.*$) {
    proxy_pass https://www.someserver.com/some-thing-else/$1;
    break;
}
Run Code Online (Sandbox Code Playgroud)

So for example I'd like

https://www.originalserver.com/foo?page=5
Run Code Online (Sandbox Code Playgroud)

to redirect to

https://www.someserver.com/some-thing-else/foo?page=5
Run Code Online (Sandbox Code Playgroud)

which I believed to be working; I think something else later down the chain is dropping the query_string.

So I want to output to the log file exactly what it was passed to. I tried $uri, $proxy_host, and $upstream_addr but I couldn't find anything that would return the fully qualified uri

https://www.someserver.com/some-thing-else/foo?page=5
Run Code Online (Sandbox Code Playgroud)

Instead I get:

proxy_host:  www.someserver.com 
upstream_addr:   123.45.67.890:443  
uri_path:    /foo   
uri_query:   page=5 
Run Code Online (Sandbox Code Playgroud)

I'm really new to rewrite rules, and coming from microsoft, so I've been reading the comprehensive docs for nginx and the searching the web, but I can't find an answer for this. Any help would be greatly appreciated. Thanks.

附录:这是我遇到问题的唯一 7 条规则。

附录 附录:这是我们当前的日志格式。

log_format json escape=json '{'
                              '"time_local": "$time_local",'
                              '"core": {'
                                '"site": "$server_name",'
                                '"server": "$host",'
                                '"dest_port": "$server_port",'
                                '"src_ip": "$realip_remote_addr",'
                                '"status": "$status",'
                                '"protocol": "$server_protocol",'
                                '"body_bytes_sent": "$body_bytes_sent",'
                                '"remote_addr": "$remote_addr",'
                                '"remote_user": "$remote_user",'
                                '"request": "$request",'
                                '"nginx_version": "$nginx_version",'
                                '"http": {'
                                  '"http_referer": "$http_referer",'
                                  '"http_user_agent": "$http_user_agent",'
                                  '"http_x_header": "$http_x_header",'
                                  '"uri_query": "$query_string",'
                                  '"uri_path": "$uri",'
                                  '"http_method": "$request_method",'
                                  '"response_time": "$upstream_response_time",'
                                  '"cookie": "$http_cookie",'
                                  '"request_time": "$request_time",'
                                  '"http_x_forwarded_for": 
                                  '"$http_x_forwarded_for",'
                                  '"proxy_host": "$proxy_host",'
                                  '"upstream_addr": "$upstream_addr"'
                                '}'
                              '}'
                            '}';```
Run Code Online (Sandbox Code Playgroud)

小智 4

要记录完整的请求 uri,您可以更改块log_format的内部http。将其更改为:

log_format  main  '$remote_addr - $remote_user [$time_local] "$host$request_uri" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
Run Code Online (Sandbox Code Playgroud)

示例输出:

1.1.1.1 - - [02/Aug/2019:20:32:36 +0200] "www.website.eu/index.php?param=some_param" 200 1238 "https://www.website.eu/" "Mozilla/5.0" "-"
Run Code Online (Sandbox Code Playgroud)