<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 13, 2014 at 12:00 AM, Francis Daly <span dir="ltr"><<a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">On Fri, Dec 12, 2014 at 04:00:29PM -0800, neubyr wrote:<br>
<br>
Hi there,<br>
<span class=""><br>
> I was wondering if it's possible to have separate namespaces for '/test'<br>
> and /test/'.<br>
<br>
</span>They are different requests, and different request prefixes, so yes,<br>
they can be handled in different location{}s.<br>
<span class=""><br>
>       location /test {<br>
>           root         /usr/share/nginx/test;<br>
>         }<br>
><br>
>          location /test/ {<br>
>            root         /usr/share/nginx/test-slash;<br>
>            try_files $uri default.txt;<br>
>         }<br>
><br>
> I tried above configuration, but nginx adds trailing slash to all '/test'<br>
> requests before they get processed by location directives. So all requests<br>
> are going to '/test/' location.<br>
<br>
</span>Have you evidence of this unexpected behaviour?<br>
<br>
A trailing slash should not be added by nginx before location{}-matching.<br>
<span class=""><br>
> Is there any way to get separate namespace for /test and /test/ ? This not<br>
> for real world website. I am trying to learn more about location directive.<br>
<br>
</span>What you have should do it. But I am not clear on what precisely you<br>
wish to happen.<br>
<br>
What request do you make? (Presumably something like "curl -i<br>
<a href="http://localhost/test" target="_blank">http://localhost/test</a>" or "curl -i <a href="http://localhost/testA" target="_blank">http://localhost/testA</a>")<br>
<br>
What response do you get? (A http redirect? Or perhaps the content of<br>
a particular file on your filesystem?)<br>
<br>
What response do you want? (The content of a different file on your<br>
filesystem? Name the files, so it is clear where the expectation and<br>
the result are different)<br>
<br>
For what it's worth, enabling the debug log can show lots about what<br>
the location-matching engine is actually doing during a request.<br>
<span class=""><font color="#888888"><br>        <br></font></span></blockquote><div><br></div><div>Thank you for pointing out debugging log. I think that helped in explaining this behavior. </div><div><br></div><div>It seems like nginx is adding slash as uri name matches with corresponding directory and not file name. I thought nginx will return 404 in this case, but it adds trailing slash when matching directory is found. </div><div><br></div><div>After adding trailing slash uri becomes /test/ and hence it matches next location block.</div><div><br></div><div>Hope my understanding of debugging log is correct. Let me know if I  am missing anything. </div><div><br></div><div>Below is a snippet from debug log.</div><div><br></div><div><br></div><div><div>2014/12/13 23:20:00 [debug] 15839#0: epoll: fd:6 ev:0001 d:00007F0AB9F9E010</div><div>2014/12/13 23:20:00 [debug] 15839#0: accept on <a href="http://0.0.0.0:80">0.0.0.0:80</a>, ready: 0</div><div>2014/12/13 23:20:00 [debug] 15839#0: posix_memalign: 00007F0ABBA0C440:256 @16</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 accept: 50.136.134.241 fd:3</div><div>2014/12/13 23:20:00 [debug] 15839#0: posix_memalign: 00007F0ABBA27070:256 @16</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 event timer add: 3: 60000:1418512860643</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 reusable connection: 1</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 epoll add event: fd:3 op:1 ev:80002001</div><div>2014/12/13 23:20:00 [debug] 15839#0: timer delta: 129801</div><div>2014/12/13 23:20:00 [debug] 15839#0: posted events 0000000000000000</div><div>2014/12/13 23:20:00 [debug] 15839#0: worker cycle</div><div>2014/12/13 23:20:00 [debug] 15839#0: epoll timer: 60000</div><div>2014/12/13 23:20:00 [debug] 15839#0: epoll: fd:3 ev:0001 d:00007F0AB9F9E1C1</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http wait request handler</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 malloc: 00007F0ABB99BC90:1024</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 recv: fd:3 77 of 1024</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 reusable connection: 0</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 posix_memalign: 00007F0ABB9E6EE0:4096 @16</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http process request line</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http request line: "GET /test HTTP/1.1"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http uri: "/test"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http args: ""</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http exten: ""</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http process request header line</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http header: "User-Agent: curl/7.30.0"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http header: "Host: <a href="http://example.org">example.org</a>"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http header: "Accept: */*"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http header done</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 event timer del: 3: 1418512860643</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 0</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 1</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/50x.html"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/test"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 using configuration "/test"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http cl:-1 max:1048576</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 3</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 post rewrite phase: 4</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 5</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 6</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 7</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 8</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 9</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 10</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 post access phase: 11</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 try files phase: 12</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http script var: "/test"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 trying to use file: "/test" "/usr/share/nginx/test/test"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 trying to use file: "/test/default.txt" "/usr/share/nginx/test/test/default.txt"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 internal redirect: "/test/default.txt?"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 1</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/50x.html"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/test"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 using configuration "/test/"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http cl:-1 max:1048576</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 3</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 post rewrite phase: 4</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 5</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 6</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 7</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 8</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 9</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 10</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 post access phase: 11</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 try files phase: 12</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 posix_memalign: 00007F0ABB9A8200:4096 @16</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http script var: "/test/default.txt"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 trying to use file: "/test/default.txt" "/usr/share/nginx/test-slash/test/default.txt"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 try file uri: "/test/default.txt"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 13</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 14</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 15</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 16</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 17</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 18</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http filename: "/usr/share/nginx/test-slash/test/default.txt"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 add cleanup: 00007F0ABB9A8260</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http static fd: 10</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http set discard body</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 xslt filter header</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 HTTP/1.1 200 OK</div><div>Server: nginx/1.6.2</div><div>Date: Sat, 13 Dec 2014 23:20:00 GMT</div><div>Content-Type: text/plain</div><div>Content-Length: 19</div><div>Last-Modified: Sat, 13 Dec 2014 23:17:22 GMT</div><div>Connection: keep-alive</div><div>ETag: "548cc902-13"</div><div>Accept-Ranges: bytes</div><div><br></div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 write new buf t:1 f:0 00007F0ABB9A8430, pos 00007F0ABB9A8430, size: 236 file: 0, size: 0</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http write filter: l:0 f:0 s:236</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http output filter "/test/default.txt?"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 http copy filter: "/test/default.txt?"</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 image filter</div><div>2014/12/13 23:20:00 [debug] 15839#0: *6 xslt filter body</div></div><div>...</div><div>...</div><div><br></div><div><br></div><div>---</div><div>Thanks,</div><div>- N <br></div><div><br></div><div><br></div><div><br></div><div>  </div></div></div></div>