2

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;
       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/foo

gives a Path Resolve error.

chicks
  • 1,911
  • 1
  • 13
  • 29
fbielejec
  • 183
  • 5

2 Answers2

1

One could replace

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;
030
  • 13,383
  • 17
  • 76
  • 178
0

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 / {
    proxy_pass http://127.0.0.1:8080/ipns/QmdpoFuwY/;
}

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.

cnst
  • 101
  • 1