patternMinor
Nginx /foo and /foo/ redirects
Viewed 0 times
andredirectsnginxfoo
Problem
I want both http://domain/foo and http://domain/foo/ requests to serve a given resource.
Here's the relevant part:
with this config only:
returns a resource while:
gives a
Here's the relevant part:
location / {
rewrite /(.*) /ipns/QmdpoFuwY/$1 break;
proxy_pass http://127.0.0.1:8080;
}with this config only:
curl -X GET http://domain.io/foo/returns a resource while:
curl -X GET http://domain.io/foogives a
Path Resolve error.Solution
One could replace
with
and try again.
The issue was solved by inspecting the logs. If for example one navigated to
It turned out that the regex did not match
rewrite /(.*) /ipns/QmdpoFuwY/$1 break;with
rewrite ^(.*[^/]) /ipns/QmdpoFuwY/$1 break;and try again.
The issue was solved by inspecting the logs. If for example one navigated to
/foo/ instead of /foo/ the log indicated:2017/10/15 14:51:28 [error] 7#7: *1 "/etc/nginx/html/index.html/foo.html" is not found (20: Not a directory)It turned out that the regex did not match
/foo/. One could also enable the rewrite logging to facilitate debugging:rewrite_log on;Code Snippets
rewrite /(.*) /ipns/QmdpoFuwY/$1 break;rewrite ^(.*[^/]) /ipns/QmdpoFuwY/$1 break;2017/10/15 14:51:28 [error] 7#7: *1 "/etc/nginx/html/index.html/foo.html" is not found (20: Not a directory)rewrite_log on;Context
StackExchange DevOps Q#2312, answer score: 1
Revisions (0)
No revisions yet.