proxy_pass with variable removes uri

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

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;
        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 is forwarded to without the "/something"
But, if I hard code the proxy_pass url, like this:
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:,248124,248124#msg-248124

More information about the nginx mailing list