stop automatic trailing slash addition

neubyr neubyr at gmail.com
Sat Dec 13 23:53:32 UTC 2014


On Sat, Dec 13, 2014 at 12:00 AM, Francis Daly <francis at daoine.org> wrote:
>
> On Fri, Dec 12, 2014 at 04:00:29PM -0800, neubyr wrote:
>
> Hi there,
>
> > I was wondering if it's possible to have separate namespaces for '/test'
> > and /test/'.
>
> They are different requests, and different request prefixes, so yes,
> they can be handled in different location{}s.
>
> >       location /test {
> >           root         /usr/share/nginx/test;
> >         }
> >
> >          location /test/ {
> >            root         /usr/share/nginx/test-slash;
> >            try_files $uri default.txt;
> >         }
> >
> > I tried above configuration, but nginx adds trailing slash to all '/test'
> > requests before they get processed by location directives. So all
> requests
> > are going to '/test/' location.
>
> Have you evidence of this unexpected behaviour?
>
> A trailing slash should not be added by nginx before location{}-matching.
>
> > Is there any way to get separate namespace for /test and /test/ ? This
> not
> > for real world website. I am trying to learn more about location
> directive.
>
> What you have should do it. But I am not clear on what precisely you
> wish to happen.
>
> What request do you make? (Presumably something like "curl -i
> http://localhost/test" or "curl -i http://localhost/testA")
>
> What response do you get? (A http redirect? Or perhaps the content of
> a particular file on your filesystem?)
>
> What response do you want? (The content of a different file on your
> filesystem? Name the files, so it is clear where the expectation and
> the result are different)
>
> For what it's worth, enabling the debug log can show lots about what
> the location-matching engine is actually doing during a request.
>
>
>

Thank you for pointing out debugging log. I think that helped in explaining
this behavior.

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.

After adding trailing slash uri becomes /test/ and hence it matches next
location block.

Hope my understanding of debugging log is correct. Let me know if I  am
missing anything.

Below is a snippet from debug log.


2014/12/13 23:20:00 [debug] 15839#0: epoll: fd:6 ev:0001 d:00007F0AB9F9E010
2014/12/13 23:20:00 [debug] 15839#0: accept on 0.0.0.0:80, ready: 0
2014/12/13 23:20:00 [debug] 15839#0: posix_memalign: 00007F0ABBA0C440:256
@16
2014/12/13 23:20:00 [debug] 15839#0: *6 accept: 50.136.134.241 fd:3
2014/12/13 23:20:00 [debug] 15839#0: posix_memalign: 00007F0ABBA27070:256
@16
2014/12/13 23:20:00 [debug] 15839#0: *6 event timer add: 3:
60000:1418512860643
2014/12/13 23:20:00 [debug] 15839#0: *6 reusable connection: 1
2014/12/13 23:20:00 [debug] 15839#0: *6 epoll add event: fd:3 op:1
ev:80002001
2014/12/13 23:20:00 [debug] 15839#0: timer delta: 129801
2014/12/13 23:20:00 [debug] 15839#0: posted events 0000000000000000
2014/12/13 23:20:00 [debug] 15839#0: worker cycle
2014/12/13 23:20:00 [debug] 15839#0: epoll timer: 60000
2014/12/13 23:20:00 [debug] 15839#0: epoll: fd:3 ev:0001 d:00007F0AB9F9E1C1
2014/12/13 23:20:00 [debug] 15839#0: *6 http wait request handler
2014/12/13 23:20:00 [debug] 15839#0: *6 malloc: 00007F0ABB99BC90:1024
2014/12/13 23:20:00 [debug] 15839#0: *6 recv: fd:3 77 of 1024
2014/12/13 23:20:00 [debug] 15839#0: *6 reusable connection: 0
2014/12/13 23:20:00 [debug] 15839#0: *6 posix_memalign:
00007F0ABB9E6EE0:4096 @16
2014/12/13 23:20:00 [debug] 15839#0: *6 http process request line
2014/12/13 23:20:00 [debug] 15839#0: *6 http request line: "GET /test
HTTP/1.1"
2014/12/13 23:20:00 [debug] 15839#0: *6 http uri: "/test"
2014/12/13 23:20:00 [debug] 15839#0: *6 http args: ""
2014/12/13 23:20:00 [debug] 15839#0: *6 http exten: ""
2014/12/13 23:20:00 [debug] 15839#0: *6 http process request header line
2014/12/13 23:20:00 [debug] 15839#0: *6 http header: "User-Agent:
curl/7.30.0"
2014/12/13 23:20:00 [debug] 15839#0: *6 http header: "Host: example.org"
2014/12/13 23:20:00 [debug] 15839#0: *6 http header: "Accept: */*"
2014/12/13 23:20:00 [debug] 15839#0: *6 http header done
2014/12/13 23:20:00 [debug] 15839#0: *6 event timer del: 3: 1418512860643
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 0
2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 1
2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/50x.html"
2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/test"
2014/12/13 23:20:00 [debug] 15839#0: *6 using configuration "/test"
2014/12/13 23:20:00 [debug] 15839#0: *6 http cl:-1 max:1048576
2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 3
2014/12/13 23:20:00 [debug] 15839#0: *6 post rewrite phase: 4
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 5
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 6
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 7
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 8
2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 9
2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 10
2014/12/13 23:20:00 [debug] 15839#0: *6 post access phase: 11
2014/12/13 23:20:00 [debug] 15839#0: *6 try files phase: 12
2014/12/13 23:20:00 [debug] 15839#0: *6 http script var: "/test"
2014/12/13 23:20:00 [debug] 15839#0: *6 trying to use file: "/test"
"/usr/share/nginx/test/test"
2014/12/13 23:20:00 [debug] 15839#0: *6 trying to use file:
"/test/default.txt" "/usr/share/nginx/test/test/default.txt"
2014/12/13 23:20:00 [debug] 15839#0: *6 internal redirect:
"/test/default.txt?"
2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 1
2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/50x.html"
2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/test"
2014/12/13 23:20:00 [debug] 15839#0: *6 test location: "/"
2014/12/13 23:20:00 [debug] 15839#0: *6 using configuration "/test/"
2014/12/13 23:20:00 [debug] 15839#0: *6 http cl:-1 max:1048576
2014/12/13 23:20:00 [debug] 15839#0: *6 rewrite phase: 3
2014/12/13 23:20:00 [debug] 15839#0: *6 post rewrite phase: 4
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 5
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 6
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 7
2014/12/13 23:20:00 [debug] 15839#0: *6 generic phase: 8
2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 9
2014/12/13 23:20:00 [debug] 15839#0: *6 access phase: 10
2014/12/13 23:20:00 [debug] 15839#0: *6 post access phase: 11
2014/12/13 23:20:00 [debug] 15839#0: *6 try files phase: 12
2014/12/13 23:20:00 [debug] 15839#0: *6 posix_memalign:
00007F0ABB9A8200:4096 @16
2014/12/13 23:20:00 [debug] 15839#0: *6 http script var: "/test/default.txt"
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"
2014/12/13 23:20:00 [debug] 15839#0: *6 try file uri: "/test/default.txt"
2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 13
2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 14
2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 15
2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 16
2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 17
2014/12/13 23:20:00 [debug] 15839#0: *6 content phase: 18
2014/12/13 23:20:00 [debug] 15839#0: *6 http filename:
"/usr/share/nginx/test-slash/test/default.txt"
2014/12/13 23:20:00 [debug] 15839#0: *6 add cleanup: 00007F0ABB9A8260
2014/12/13 23:20:00 [debug] 15839#0: *6 http static fd: 10
2014/12/13 23:20:00 [debug] 15839#0: *6 http set discard body
2014/12/13 23:20:00 [debug] 15839#0: *6 xslt filter header
2014/12/13 23:20:00 [debug] 15839#0: *6 HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sat, 13 Dec 2014 23:20:00 GMT
Content-Type: text/plain
Content-Length: 19
Last-Modified: Sat, 13 Dec 2014 23:17:22 GMT
Connection: keep-alive
ETag: "548cc902-13"
Accept-Ranges: bytes

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
2014/12/13 23:20:00 [debug] 15839#0: *6 http write filter: l:0 f:0 s:236
2014/12/13 23:20:00 [debug] 15839#0: *6 http output filter
"/test/default.txt?"
2014/12/13 23:20:00 [debug] 15839#0: *6 http copy filter:
"/test/default.txt?"
2014/12/13 23:20:00 [debug] 15839#0: *6 image filter
2014/12/13 23:20:00 [debug] 15839#0: *6 xslt filter body
...
...


---
Thanks,
- N
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20141213/c9456fda/attachment.html>


More information about the nginx mailing list