Nginx trailing slash in proxy pass url

I guess you use proxy_pass without URI. In that case nginx pass original URI as it was, not normalized one. So you should use proxy_pass http://backend/;

UPDATE

So I was right. Just add URI part to proxy_pass like this:

location = /a {
    proxy_pass http://127.0.0.1:8080/a;
    ...
}

location ^~ /a/ {
    proxy_pass http://127.0.0.1:8080/a/;
    ...
}

As stated in nginx documentation if proxy_pass used without URI (i.e. without path after server:port) nginx will put URI from original request exactly as it was with all double slashes, ../ and so on.

On the other side, URI in proxy_pass acts like alias directive, means nginx will replace part that matches location prefix (in our case it’s /a in first location and /a/ is second) with URI in proxy_pass directive (which I intentionally made the same as location prefix) so URI will be the same as requested but normalized (without double slashes and all that staff). Be careful with trailing slashes. Nginx replaces part literally and you could end up with some strange url.

Here is an example with trailing slash in location, but no trailing slash in proxy_pass.

location /one/ {
    proxy_pass http://127.0.0.1:8080/two;
    ...
}

If you go to address http://yourserver.com/one/path/here?param=1 nginx will proxy request to http://127.0.0.1/twopath/here?param=1. See how two and path concatenates.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)