Answers: <p>One could replace</p>
  
  <pre><code>rewrite /(.*) /ipns/QmdpoFuwY/$1 break;
  </code></pre>
  
  <p>with</p>
  
  <pre><code>rewrite ^(.*[^/]) /ipns/QmdpoFuwY/$1 break;
  </code></pre>
  
  <p>and try again.</p>
  
  <p>The issue was solved by inspecting the logs. If for example one navigated to <code>/foo/</code> instead of <code>/foo/</code> the log indicated:</p>
  
  <pre><code>2017/10/15 14:51:28 [error] 7#7: *1 "/etc/nginx/html/index.html/foo.html" is not found (20: Not a directory)
  </code></pre>
  
  <p>It turned out that the regex did not match <code>/foo/</code>. One could also enable the rewrite logging to facilitate debugging:</p>
  
  <pre><code>rewrite_log on;
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2017-10-16T13:03:54.597Z
Answers: 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.
Answers: fbielejec
Answers: CC BY-SA 3.0
Answers: 2017-10-15T14:37:09.083Z
Answers: 2017-10-15T14:55:45.317Z
Answers: 2017-10-15T14:55:45.317Z
Answers: 030
Answers: <p>Your nginx code is incorrect, for example, because you're effectively losing the extra functionality afforded by <a href="http://nginx.org/r/proxy_redirect" rel="nofollow noreferrer">http://nginx.org/r/proxy_redirect</a> default value of <code>default</code>.</p>
  
  <p>As per the documentation at <a href="http://nginx.org/r/proxy_pass" rel="nofollow noreferrer">http://nginx.org/r/proxy_pass</a>, the correct way would be to map location on the front-end and back-end directly within the <code>proxy_pass</code>, especially if you don't need to be using any variables:</p>
  
  <pre><code>location / {
      proxy_pass http://127.0.0.1:8080/ipns/QmdpoFuwY/;
  }
  </code></pre>
  
  <hr>
  
  <p>Otherwise, back to your question, there is absolutely no reason to have <code>/foo</code> and <code>/foo/</code> point to the same resource.</p>
  
  <p>In fact, it would be perfectly legal for one to be internally expanded to <code>/foo.html</code>, whereas for the other to <code>/foo/index.html</code>, so, the fact that different results are returned is entirely normal, and doesn't need to be fixed.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-11-27T02:26:41.640Z
Answers: 2017-11-27T02:26:41.640Z
Answers: cnst
Body: <p>I want both <a href="http://domain/foo" rel="nofollow noreferrer">http://domain/foo</a> and <a href="http://domain/foo/" rel="nofollow noreferrer">http://domain/foo/</a> requests to serve a given resource. 
  Here's the relevant part:</p>
  
  <pre><code>location / {
         rewrite /(.*) /ipns/QmdpoFuwY/$1 break;
         proxy_pass http://127.0.0.1:8080;
  }
  </code></pre>
  
  <p>with this config only:</p>
  
  <pre><code>curl -X GET http://domain.io/foo/
  </code></pre>
  
  <p>returns a resource while:</p>
  
  <pre><code>curl -X GET http://domain.io/foo
  </code></pre>
  
  <p>gives a <code>Path Resolve</code> error.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-10-15T11:35:42.043Z
Comments: What does the log indicate?
Comments: 030
Tags: <amazon-ec2><servers><http>
Title: Nginx /foo and /foo/ redirects
UserDisplayName: fbielejec
ThreadText: # Nginx /foo and /foo/ redirects
  
  (Asked by: username_0 on 2017-10-13)
  
  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.
  
  **Tags:** amazon-ec2, servers, http
  
  > **Comments:**
  > **username_1**: What does the log indicate?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-10-15. Score: 1 | Accepted answer
  
  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;
  
  ```
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  ### Answer by username_2 on 2017-11-27. Score: 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.
  
  
  ---
  
  