# Reverse proxy, proxy\_pass

**URL:** <https://www.ruby-forum.com/t/reverse-proxy-proxy-pass/243790>\
**Category:** NGINX\
**Created:** [January 7, 2016, 12:52am UTC](https://www.ruby-forum.com/t/reverse-proxy-proxy-pass/243790 "2016-01-07T00:52:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [January 7, 2016, 12:52am UTC](https://www.ruby-forum.com/t/reverse-proxy-proxy-pass/243790/1 "2016-01-07T00:52:48Z")

</div>

Hi there,

Here is a part of my nginx config file:

location /test/ {  
proxy\_pass [http://localhost:1024/](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.

---

<div class="post-metadata">

**Author:** ![Amir\_Kaivani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8edcca/32.png) [@Amir\_Kaivani](https://www.ruby-forum.com/u/Amir_Kaivani)\
**Post date:** [January 8, 2016, 7:03pm UTC](https://www.ruby-forum.com/t/reverse-proxy-proxy-pass/243790/2 "2016-01-08T19:03:31Z")

</div>

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.

> **[nginx](http://nginx.org/)**
