Please help with proxy_pass and trailing slash!

Roddick nginx-forum at
Wed Mar 14 17:05:55 UTC 2012

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

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/;

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:,223839,223839#msg-223839

More information about the nginx mailing list