Reputation: 1
I am serving static content with Nginx, and I have a question about the behavior of requests without a trailing slash. While everything works fine in Chrome, Safari behaves differently.
When I access https://example.com/test/foo
in Safari, the following error is displayed:
Cannot Open Page
Safari can’t open the page “https://example.com/test/foo” because the server unexpectedly dropped the connection. This sometimes occurs when the server is busy. Wait for a few minutes, and then try again.
The URL remains https://example.com/test/foo
, and adding a trailing slash manually still results in the same error. However, if I open a new tab and access https://example.com/test/foo/
directly, the page loads without any issues.
Here’s my Nginx configuration:
location /test {
root /var/www/html;
try_files $uri $uri/ =404;
}
From my understanding, Nginx should redirect requests without a trailing slash to the trailing slash version of the URL, but it seems like that is not happening.
In Chrome, the redirection works as expected, and the page is displayed correctly. However, I noticed that Chrome makes two requests: one to https://example.com/test/foo
and another to http://example.com/test/foo/
. The second request responds with a 307 status code, with the Location
header pointing to https://example.com/test/foo/
. This HTTP-to-HTTPS redirection is a bit concerning as well.
What can I do to make Safari handle this situation properly and load the page correctly? Any advice or insights would be greatly appreciated!
I expected Nginx to redirect requests without a trailing slash to the trailing slash version of the URL (e.g., /test/foo
→ /test/foo/
) as it normally does. I tried accessing the URL in Safari, assuming it would work the same way it does in Chrome. However, in Safari, the request fails with a connection error, and no redirection happens. In Chrome, the redirection works properly. I also tried adding a trailing slash manually in Safari (/test/foo/
), but it still resulted in the same error unless accessed from a new tab. I expected the behavior to be consistent across browsers.
Upvotes: 0
Views: 22