proxy_pass with variable removes uri

luckyswede nginx-forum at nginx.us
Wed Mar 5 10:47:58 UTC 2014


Hi,
I have a conf with two virtual hosts and a proxy-pass that is dependent on
which host the request arrived to, like this:

    server {
        listen 80;
        server_name x.com y.com;
        resolver 8.8.8.8;
        root /var/www/html;

        location / {
	    # whatever
        }

        location /api/ {
            proxy_pass http://api.$host/;
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
        }
    }

Note the trailing "/" on proxy_pass which should forward the uri untouched,
stripping out "/api". However, the uri is not forwarded at all, e.g. GET
http://x.com/api/somehing is forwarded to api.x.com without the "/something"
part.
But, if I hard code the proxy_pass url, like this:
            proxy_pass http://api.x.com/;
it works, the uri is properly forwarded.

Doesn't proxy_pass have proper support for variables or have I done
something wrong?

Many thanks / Jonas

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,248124,248124#msg-248124



More information about the nginx mailing list