I have a location
location /pass/ {
proxy_pass http://localhost:12345/;
}
So it is supposed to proxify urls http://example.com/pass/whatever
to http://localhost:12345/whatever
The thing I don't like about it is that nginx is automatically adding slash to
http://example.com/pass
and makes it http://example.com/pass/
via 301 redirect
How can I simply avoid this behavior. I want /pass
without trailing slash to go to another location. Thanks in advance!
Best Answer
There's a special case where a
proxy_pass
with alocation
ending in/
would result in an automatic implicit301
redirect without going to the backend; you have to create an explicitlocation
without the trailing slash to avoid this:E.g., you gotta create an explicit
/pass
location
in addition to the existing/pass/
one, otherwise, an implicitlocation /pass {return 301 /pass/…;}
will be created for you.However, are you sure you actually want to do what you're trying to do? If you're going to omit a redirect from
/pass
to/pass/
, then relative paths aren't going to work. Some newer browsers also have a tendency to feature defective UI/UX that may not present the trailing slash to the user, which may make things even more confusing when trying to troubleshoot the distinction.