Welcome! Log In Create A New Profile

Advanced

Re: proxy_pass with variable removes uri

Maxim Dounin
March 05, 2014 06:24AM
Hello!

On Wed, Mar 05, 2014 at 05:47:58AM -0500, luckyswede wrote:

> 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?

The "proxy_pass" directive, if used with variables, specifies
_full_ URI to request, see http://nginx.org/r/proxy_pass:

: A server name, its port and the passed URI can also be specified
: using variables:
:
: proxy_pass http://$host$uri;
:
: or even like this:
:
: proxy_pass $request;

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

proxy_pass with variable removes uri

luckyswede March 05, 2014 05:47AM

Re: proxy_pass with variable removes uri

Maxim Dounin March 05, 2014 06:24AM

Re: proxy_pass with variable removes uri

luckyswede March 05, 2014 07:23AM

Re: proxy_pass with variable removes uri

Maxim Dounin March 05, 2014 07:34AM

Re: proxy_pass with variable removes uri

luckyswede March 05, 2014 07:46AM

Re: proxy_pass with variable removes uri

Maxim Dounin March 05, 2014 08:44AM

Re: proxy_pass with variable removes uri

Francis Daly March 05, 2014 07:44AM

Re: proxy_pass with variable removes uri

Valentin V. Bartenev March 05, 2014 06:24AM

Re: proxy_pass with variable removes uri

luckyswede March 05, 2014 06:29AM

Re: proxy_pass with variable removes uri

luckyswede March 05, 2014 07:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 79
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready