我得到了以下nginx-conf:
http {
log_format upstream_logging '[proxied request] '
'$server_name$request_uri -> $upstream_addr';
access_log /dev/stdout upstream_logging;
server {
listen 80;
server_name localhost;
location ~ /test/(.*)/foo {
proxy_pass http://127.0.0.1:3000/$1;
}
}
}
当我点击:
http://localhost/test/bar/foo
我的实际输出是:
[proxied request] localhost/test/bar/foo -> 127.0.0.1:3000
而我的预期输出是:
[proxied request] localhost/test/bar/foo -> 127.0.0.1:3000/bar
有没有一个变量或方法可以在日志中生成实际的代理URI?
如果不是生产版,您可以在所需的本地地址和端口(而不是真实的(上启动最简单的侦听服务器后测试nginx发送的内容:
$ nc -l 127.0.0.1 3000
POST /some/uri HTTP/1.0
Host: 127.0.0.1
Connection: close
Content-Length: 14
some payload
当nc
运行时,可以手动输入HTTP/1.1 200 OK
,然后输入2条新行来模拟响应。