Opened 10 years ago
Closed 10 years ago
#645 closed defect (fixed)
proxy_pass does not work as expected in if context
Reported by: | Xiaochen Wang | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | nginx-core | Version: | 1.7.x |
Keywords: | Cc: | ||
uname -a: | |||
nginx -V: |
nginx version: nginx/1.7.7
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52) TLS SNI support enabled configure arguments: --with-debug --prefix=/path/to/hg-nginx-output --with-http_spdy_module --with-cc-opt=-O0 --with-http_ssl_module --with-openssl=/path/to/openssl-1.0.1h |
Description
With nginx configure as following, if requesting uri '/?test=1', nginx proxy this request to 127.0.0.1:8082, not 127.0.0.1:8083.
server { listen 80; location / { if ($arg_test) { proxy_pass http://127.0.0.1:8083; } set $p 8082; proxy_pass http://127.0.0.1:$p; } }
Another example as following, if requesting uri '/?test=1', nginx proxy this request with ssl enabled, which is not as expected.
server { listen 80; location / { if ($arg_test) { proxy_pass http://127.0.0.1:8083; } proxy_pass https://127.0.0.1:8083; } }
Attachments (2)
Change History (6)
by , 10 years ago
Attachment: | nginx-proxy-patch-test.conf added |
---|
comment:1 by , 10 years ago
by , 10 years ago
Attachment: | nginx-proxy.patch added |
---|
comment:2 by , 10 years ago
I updated the patch because the previous one did not respect cases when there were no new proxy_pass directive declaration in if-block. Current logic is as simple as:
- Try to inherit proxy_lengths and proxy_values only if upstream.upstream is NULL
- If both proxy_lengths/proxy_values and upstream.upstream are NULL (the case when proxy_pass is not defined again in if-block) then all must be tried to inherit (same behaviour as before the patches).
- If upstream.ssl is NULL then it must be inherited only if upstream.upstream is NULL (because in case of proxy_lengths it is always set).
Note:
See TracTickets
for help on using tickets.
Hi.
Just 2 days ago i put a comprehensive article about why it happens in my blog (see http://lin-techdet.blogspot.ru/2014/10/nginx-proxypass.html) (it is written in Russian!).
I attached a patch against version 1.7.6 that solves the issue and a configuration for testing it.
Cheers, Alexey.