# Please help with proxy\_pass and trailing slash!

**URL:** <https://www.ruby-forum.com/t/please-help-with-proxy-pass-and-trailing-slash/217845>\
**Category:** NGINX\
**Created:** [March 14, 2012, 6:06pm UTC](https://www.ruby-forum.com/t/please-help-with-proxy-pass-and-trailing-slash/217845 "2012-03-14T18:06:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 14, 2012, 6:06pm UTC](https://www.ruby-forum.com/t/please-help-with-proxy-pass-and-trailing-slash/217845/1 "2012-03-14T18:06:48Z")

</div>

I have a php site with location /app served by Java app server on same  
server port 9001

What is in /app/ should become / (root) for Java app server

I have this in config:

server {  
…  
index index.html index.htm index.php;

location /app {

```
            proxy_pass http://localhost:9001;
            proxy_next_upstream error timeout invalid_header

```

http\_500 http\_502 http\_503;

```
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For

```

$proxy\_add\_x\_forwarded\_for;

```
            proxy_set_header X-Forwarded-Proto https;

            proxy_redirect off;
  }

 location / {
          # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.php?$args;
    }

```

location ~ index.php$ {

```
    try_files $uri =404;

    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_pass 127.0.0.1:9000;  
}  
}

with this configuration, Java server receives requests like “GET /app/”  
while it should receive “GET /”

If I add trailing slash to proxy\_pass:

proxy\_pass [http://localhost:9001/](http://localhost:9001/);

Then java server receives “GET //” and unable to serve that either.

Do I need to involve rewrite here ? And how? or extra trailing slash is  
caused by other rewrite rules somehow?

Thank you!

Posted at Nginx Forum:

> **[Please help with proxy\_pass and trailing slash!](https://forum.nginx.org/read.php?2,223839,223839#msg-223839)**
>
> I have a php site with location /app served by Java app server on same server port 9001 What is in /app/ should become / (root) for Java app server I have this in config: server { ... index index.html index.htm index.php; loc

---

<div class="post-metadata">

**Author:** ![Roddick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b2d939/32.png) [@Roddick](https://www.ruby-forum.com/u/Roddick)\
**Post date:** [March 14, 2012, 7:06pm UTC](https://www.ruby-forum.com/t/please-help-with-proxy-pass-and-trailing-slash/217845/2 "2012-03-14T19:06:28Z")

</div>

On Wednesday 14 March 2012 21:05:55 Roddick wrote:

> ```
> proxy_set_header X-Forwarded-Proto https;
> 
> proxy_redirect off;
> }
> 
> location / {
> # First attempt to serve request as file, then
> # as directory, then fall back to index.html
> try_files $uri $uri/ /index.php?$args;
> }
> 
> ```

Just a side note, you don’t need explicit set $args here.

```
try_files $uri $uri/ /index.php;

```

> }  
> Do I need to involve rewrite here ? And how? or extra trailing slash is  
> caused by other rewrite rules somehow?

Documentation already has answers to your questions:

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

E.g., in your case:

```
location /app/ {
    ...
    proxy_pass http://localhost:9001/;
}

```

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Roddick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b2d939/32.png) [@Roddick](https://www.ruby-forum.com/u/Roddick)\
**Post date:** [March 15, 2012, 5:08am UTC](https://www.ruby-forum.com/t/please-help-with-proxy-pass-and-trailing-slash/217845/3 "2012-03-15T05:08:29Z")

</div>

## Valentin V. Bartenev Wrote:

> $args here.
> 
> > ```
> > fastcgi_param SCRIPT_FILENAME
> > 
> > ```
> 
> Documentation already has answers to your
> 
> wbr, Valentin V. Bartenev

Thanks Valentin.

I get it now! I had  
location /app {

and it should be  
location /app/ {

with trailing slash. Weird that it’s sensitive for that slash there.

Thanks.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,223839,223859#msg-223859](http://forum.nginx.org/read.php?2,223839,223859#msg-223859)

---

<div class="post-metadata">

**Author:** ![Roddick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b2d939/32.png) [@Roddick](https://www.ruby-forum.com/u/Roddick)\
**Post date:** [March 15, 2012, 5:19am UTC](https://www.ruby-forum.com/t/please-help-with-proxy-pass-and-trailing-slash/217845/4 "2012-03-15T05:19:08Z")

</div>

Am 15.03.2012 11:08 schrieb “Roddick” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > ```
> > > try_files $uri $uri/
> > > 
> > > ```
> > > 
> > > with this configuration, Java server receives  
> > > Do I need to involve rewrite here ? And how? or
> 
> I get it now! I had  
> location /app {
> 
> and it should be  
> location /app/ {
> 
> with trailing slash. Weird that it’s sensitive for that slash there.

Trivia: “location /app { … }” will match url "  
[http://domain.com/appwhatever](http://domain.com/appwhatever)"
