Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

I need help understanding trailing slash behaviour in Nginx

I'm setting up nginx as a reverse proxy for squaremap (a world map viewer for Minecraft servers) and encountering unexpected behavior with trailing slashes. I've followed the squaremap documentation for serving with nginx acting as a reverse proxy (https://github.com/jpenilla/squaremap/wiki/Internal-vs-External-Web-Server), but I'm confused by the results. Here's what I've tried:

squaremap is running at 127.0.0.1:39000

Configuration:

  1. location /squaremap {
        proxy_pass http://127.0.0.1:39000;
    }
    

    Result: Accessing https://example.com/squaremap returns a 404 error.

  2. location /squaremap {
        proxy_pass http://127.0.0.1:39000/;
    }
    

    Result: https://example.com/squaremap shows a blank page, but https://example.com/squaremap/ works fine.

  3. location /squaremap/ {
        proxy_pass http://127.0.0.1:39000/;
    }
    

    Result: https://example.com/squaremap redirects to https://example.com/squaremap/ and then displays the web interface. https://example.com/squaremap/ works as expected.

In my attempt to figure out what was happening, I read part of the nginx documentation on proxy_pass. However, I'm not sure if my interpretation is correct. My understanding is:

  1. If there's no URI in the proxy_pass directive, the request URI is passed to the upstream unchanged.
  2. If there is a URI in the proxy_pass directive, the part of the request matching the location directive is substituted by the value of the URI in the proxy_pass directive.

Based on this, I created a table of what I think is happening in each of the above cases:

Case Original Request Request to Upstream Result
1 https://example.com/squaremap /squaremap Error 404
2.a https://example.com/squaremap / White page
2.b https://example.com/squaremap/ // Works
3 https://example.com/squaremap/ / Works

My questions are:

  1. Is my interpretation of how nginx processes these requests correct?
  2. Why do I get different results in cases 2a and 3, even though they seem to send the same request to the upstream?
  3. Why doesn't it work without the trailing slash, but works with it?
  4. Is there a configuration that would allow both /squaremap and /squaremap/ to work correctly without a redirect?

I'd appreciate any insights into understanding this behavior and how to properly configure nginx for this use case.

Comments

  • I had to look at the Documentation to make sure but From what I can tell, and just follow me here Okay......You aren't once from your examples using the proper Method explained by the nginx Docs, I'm sure the third party knows what they're doing But if you want to use nginx my advice is go By their Official Documentation here is the relevant part you sort of Mentioned and then you changed the last part of their sentence "by the value of the URI" well the end part No that's not what it says know what I mean, And then there There is your configuration which is again, Not following the Official Docs which clearly as I thought show the location and the URI with examples, try following and then report back:

    https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ Note that in the first example above, the address of the proxied server is followed by a URI, /link/. If the URI is specified along with the address, it replaces the part of the request URI that matches the location parameter. For example, here the request with the /some/path/page.html URI will be proxied to http://www.example.com/link/page.html. If the address is specified without a URI, or it is not possible to determine the part of URI to be replaced, the full request URI is passed (possibly, modified).

  • vsys_hostvsys_host Member, Patron Provider

    2a and 2b have to be the same on the backend. Maybe there is an issue with the CSS/JS path. Since your backend is not SSL, just run tcpdump, like tcpdump -i any -A -s 0 'tcp dst port 39000 and host 127.0.0.1'
    For universal location, try:
    location ~ ^/squaremap/?(.*)$ {
    proxy_pass http://127.0.0.1:39000/$1;
    }

Sign In or Register to comment.