I want both http://domain/foo and http://domain/foo/ requests to serve a given resource. Here's the relevant part:

location / {
       rewrite /(.*) /ipns/QmdpoFuwY/$1 break;

with this config only:

curl -X GET http://domain.io/foo/

returns a resource while:

curl -X GET http://domain.io/foo

gives a Path Resolve error.

  • What does the log indicate? – 030 Oct 15 '17 at 11:35

One could replace

rewrite /(.*) /ipns/QmdpoFuwY/$1 break;


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;
  • I did: if ($request_uri ~ ^(.*)[/]$) { rewrite /(.*) rewrite /(.*) /ipns/QmdpoFuwY/$1 break; } if ($request_uri ~ ^(.*)[^/]$) { rewrite /(.*) /ipns/QmdpoFuwY/$1/ break; } The suggested answer should also work and is less verbose. – fbielejec Oct 16 '17 at 13:03

Your nginx code is incorrect, for example, because you're effectively losing the extra functionality afforded by http://nginx.org/r/proxy_redirect default value of default.

As per the documentation at http://nginx.org/r/proxy_pass, the correct way would be to map location on the front-end and back-end directly within the proxy_pass, especially if you don't need to be using any variables:

location / {

Otherwise, back to your question, there is absolutely no reason to have /foo and /foo/ point to the same resource.

In fact, it would be perfectly legal for one to be internally expanded to /foo.html, whereas for the other to /foo/index.html, so, the fact that different results are returned is entirely normal, and doesn't need to be fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.