Opened 3 years ago

Closed 3 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


proxy_pass does not form correct URI when declared with $scheme variable:

server {
    listen 80;
    listen 443 ssl http2;


    include conf.d/ssl.conf;

    location / {
        proxy_pass              $scheme://;
        # proxy_pass    ;
        proxy_set_header        Host;
        include conf.d/proxy-params.conf;

Test request from x.x.x.x host:

Server logs following lines: - - [12/Apr/2017...] "GET /hu/ HTTP/1.0" 200 13995 "-" "curl/7.35.0" "-" 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: - - [12/Apr/2017...] "GET /hu/css/style.css HTTP/1.0" 404 328 "-" "curl/7.35.0" "-" 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 Ruslan Ermilov, 3 years ago

Try proxy_pass $scheme://$request_uri;.

comment:2 by Maxim Dounin, 3 years ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.