January 22nd 2018

linux, server, nginx

Nginx and Trailing Slashes


This is a well-known problem for nginx users: an URL points to a directory, but misses the trailing slash, which results in nginx looking for a file, not a folder, and not finding it.

But! It seems that this issue has been fixed long since: nginx does add trailing slashes automatically nowadays.

So my problem must be a different one (and all searches led me on the wrong path).

Explanation & Solution

Most browsers (in this case Firefox) hide certain details. Using surf instead, I can suddenly see that nginx creates a redirect with a trailing slash, but adds the port number to the base URL. And I'm running nginx on a non-standard port, which my router forwards to a standard port.
With that knowledge it didn't take long to find the solution:
just add port_in_redirect off; to the appropriate configuration file.
And restart the server.