Opened 8 years ago
Closed 8 years ago
#1246 closed defect (invalid)
proxy_pass does not form correct URI when declared with $scheme variable
Reported by: | Sergei Kudimov | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | nginx-core | Version: | 1.11.x |
Keywords: | Cc: | ||
uname -a: | Linux vps 3.19.0-26-generic #28~14.04.1-Ubuntu SMP Wed Aug 12 14:09:17 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux | ||
nginx -V: | nginx version: nginx/1.11.9 |
Description
proxy_pass does not form correct URI when declared with $scheme variable:
server { listen 80; listen 443 ssl http2; server_name frontend.com; include conf.d/ssl.conf; location / { proxy_pass $scheme://127.0.0.1/hu/; # proxy_pass http://127.0.0.1/hu/; proxy_set_header Host backend.com; include conf.d/proxy-params.conf; } }
Test request from x.x.x.x host:
curl http://frontend.com/css/style.css
Server logs following lines:
backend.com 127.0.0.1 - - [12/Apr/2017...] "GET /hu/ HTTP/1.0" 200 13995 "-" "curl/7.35.0" "-" frontend.com x.x.x.x - - [12/Apr/2017...] "GET /css/style.css HTTP/1.1" 200 14023 "-" "curl/7.35.0" "-"
As we see request for /css/style.css was proxied as /hu/, which is incorrect. According to documentation expected form is /hu/css/style.css.
When I have replaced $scheme://
with explicit http://
it began to work properly:
backend.com 127.0.0.1 - - [12/Apr/2017...] "GET /hu/css/style.css HTTP/1.0" 404 328 "-" "curl/7.35.0" "-" frontend.com x.x.x.x - - [12/Apr/2017...] "GET /css/style.css HTTP/1.1" 404 356 "-" "curl/7.35.0" "-"
Change History (2)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Quoting the proxy_pass
directive description:
A server name, its port and the passed URI can also be specified using variables:
proxy_pass http://$host$uri;
When using variables, you have to specify _full URI_ to be passed to an upstream server. This might be somewhat counterintuitive, but this is how it works and expected to work.
Try
proxy_pass $scheme://127.0.0.1/hu$request_uri;
.