Welcome! Log In Create A New Profile

Advanced

Re: Reverse proxy, proxy_pass

Maxim Dounin
January 08, 2016 01:04PM
Hello!

On Wed, Jan 06, 2016 at 05:52:20PM -0600, Amir Kaivani wrote:

> Hi there,
>
> Here is a part of my nginx config file:
>
> location /test/ {
> proxy_pass http://localhost:1024/;
> }
>
> If I have it as above the GET /test/xxxx request will be sent to port 1024
> as /xxxx and it also decodes the URI.
>
> I know that if I remove / from the end of proxy_pass then it'll send the
> URI without decoding special characters (such as %2F). But in this case it
> sends /test/xxxx to port 1024.
>
> So, my question is how I can get nginx to remove /test/ from the URI but
> does NOT decode special characters (such as %2F)?

How do you expect nginx to remove "/test/" without decoding
special characters? E.g., what should happen if the request is to
"/test%2F", "/t%65st/", or "/test//"?

As long as you have an answer, you can try constructing
appropriate URI to upstream request yourself by using proxy_pass
with variables. When proxy_pass is used with variables, nginx
won't try to do anything with URI specified and will pass it ass
is.

E.g., assuming all requests start with "/test/" and there are no
escaping problems:

location /test/ {
set $changed_uri "/";

if ($request_uri ~ "^/test(/.*)") {
set $changed_uri $1;
}

proxy_pass http://localhost:1024$changed_uri;
}

Note though, that such approach is likely to cause problems unless
used with care.

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

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

Reverse proxy, proxy_pass

Amir Kaivani January 06, 2016 06:54PM

Re: Reverse proxy, proxy_pass

Maxim Dounin January 08, 2016 01:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 238
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready