问题原文
原帖链接 · Andrey · CC BY-SA 3.0
I need to pass some requests to proxy (running GlassFish) with removing one section of url. For example:
https://xxx.net/jazz/MobileApi?id=2&make_id=4
Should be passed to proxy as:
http://X.X.X.X:8080/MobileApi?id=2&make_id=4
I have following Nginx configuration:
upstream vito_api {
server 178.63.X.X:8080;
}
server {
listen 80;
listen 443 ssl;
....
location ~ /jazz/(?<section>.*) {
proxy_pass http://vito_api/$section/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
But, unfortunately, request passing without parameters. So, in GlassFish access logs, I can see only:
"148.251.X.X" "NULL-AUTH-USER" "05/Jan/2015:15:18:40 +0100" "GET /MobileApi/ HTTP/1.0" 200 21
What I did wrong? How to pass URL parameters too?
Thank you.
已采纳解答
原帖链接 · Xavier Lucas · CC BY-SA 3.0
From nginx's documentation (context : prefixed location)
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.
So it can be simplified with the following :
location /jazz/ {
proxy_pass http://vito_api/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
