Request path not passed to proxy when $scheme is used in proxy_pass URI

Hi all, I’ve found a strange behaviour with proxy_pass. I’ve reduced a
simple vhost that reproduces it:

server {
location / {
proxy_pass $scheme://;

A listener on localhost:9000 receives a request, but for ‘/’ instead of
correct path. For example, curling this URI…

curl -I -X GET http://localhost:8000/test-path

… causes a “GET /” on a local listener:

nc -l 9000
GET / HTTP/1.0

If I replace $scheme with ‘http’ (i.e. “proxy_pass”),
then it works correctly:

curl -I -X GET http://localhost:8000/test-path

nc -l 9000
GET /test-path HTTP/1.0

I ran these tests on nginx-1.2.7 / OS X 10.8.3; the behaviour is the
on nginx-1.2.4 / Ubuntu 12.04 (which is where I discovered it).

Am I using $scheme incorrectly here, or could this be a bug?

Ben Hoskings

Ahh, I’ve found the answer in the proxy_pass documentation.

Module ngx_http_proxy_module – “A special case is
using variables in the proxy_pass statement: The requested URL is not
and you are fully responsible to construct the target URL yourself.”

Surprising, but now I know for next time :slight_smile: