Reverse proxy, proxy_pass

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

Thank you for your help.

Hello!

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

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 D.
http://nginx.org/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs