I have a horrible issue with Nginx. I have a service like https://td22-2.test.net/ I use Azure Frontdoor to forward requests from https://example.net/td/22-2/ to it. My Azure Rules are attached The problem is that a part of the url (/td/22-2/) is dropped ONLY when the user enters a URL without an ending slash and Nginx redirects? them to a path with a slash. For example, when I type https://example.net/td/22-2/example/path will give https://example.net/example/path/ (missing the td/22-2)
I was able to confirm with CURL that /td/22-2/example/path is sent to NGINX with GET, and NGinx returns only /example/path/
server {
listen 8080;
index index.html index.htm;
root /opt/24/www;
gzip on;
#I added this to prevent an issue when running it locally where entering a path without a slash would return a path localhost:8080, instead of 81, which is what my docker container exposes.
absolute_redirect off;
location / {
location ~* /images/*.* {
}
}
}
I've tried this, and I only added "absolute_redirect off;" to prevent an issue when running this server via docker on my local machine (docker exposes port 81, while the server uses port 8080)
Main issue- nginx was dropping part of the request path during redirects when adding a trailing slash. For example, https://example.net/td/22-2/example/path
redirected to https://example.net/example/path/
, dropping the /td/22-2/
prefix.
As earlier discussed in comments, this behavior is due to how nginx handles redirects internally. nginx, by default, constructs the Location header during redirects using its internal understanding of the request path, ignoring the forwarded prefix (/td/22-2/) from front door.
Troubleshooting steps that was involved in the process were
first test it out locally and see if everything works fine locally.
As a workaround, instead of modifying Nginx configurations, user, Dineth-Mallawarachchi rewrote the server using Rust. By using a standard web server framework (example actix-web), the issue was resolved without requiring additional configurations. The new server correctly preserved the original request path and ensured that trailing slashes were added as expected. Thanks for your contribution to the SO community, please feel free to edit / add any additional points if required from your end.