0

In my nginx config i have a location block for a subpath:

location /documentation {
        alias /usr/share/nginx/html/documentation;
        index index.html;
    try_files $uri $uri/ /documentation/index.html;

}

And technicaly, it works. However only when i navigate to http://localhost:90/documentation/. When i navigate to http://localhost:90/documentation, it redirects me to http://localhost/documentation/ which fails of course because i have lost my port.

Here is the log of the redirect: 172.24.0.1 - - [26/Feb/2024:09:12:56 +0000] "GET /documentation HTTP/1.1" 301 169 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" "-"

If anyone has a clue as to why this redirect happens?

This may be important: At this location, i'm serving a static build of a Docusaurus. and the whole setup is in a docker container.

1 Answers1

0

I found the solution myself:

Apparently nginx automatically adds a trailing slash to the uri, and does this using an absolute redirect (HTTP 301). This causes the default protocol port to be applied, in this case (http) => 80.

I added absolute_redirect off; Which causes the redirect to be a "soft" redirect, and this keeps the url intact.