aperezdc/ngx-fancyindex

Unexpected Redirection When Missing Trailing Slash to Directory

n4kre opened this issue · 1 comments

n4kre commented

Hi everyone,

I am running FancyIndex within an Nginx server block configured as follows (snippet):

listen 127.0.0.2:1234 ssl http2;
server_name www.example.org;

This is Internet facing at https://www.example.org – it is not behind a reverse proxy: I use SSLH to multiplex LAN-IP-from-this-machine:443 –, and when I try to browse https://www.example.org/dir (mind the missing trailing slash), I get a 301 redirection with an HTTP header Location set to https://www.example.org:1234/dir/.

Of course, I was hoping the redirection to be made to https://www.example.org/dir/: am I missing something?

n4kre commented

Oops: this is not related to FancyIndex…

Reading Nginx documentation, I could find a workaround to deal with this with situation where I don't have a reverse-proxy in front of FancyIndex to properly rewrite Location/ Refresh HTTP headers.

One trick is to use only relative paths in redirection. It can be achieved using this Nginx server block directive:

absolute_redirect off;

Another trick, since I am using the well-known HTTPS port, is to simply ask Nginx to not add the server port number in redirections:

port_in_redirect off;

Probably a better idea.