Welcome! Log In Create A New Profile

Advanced

Re: stop automatic trailing slash addition

Francis Daly
December 14, 2014 05:54AM
On Sat, Dec 13, 2014 at 03:53:32PM -0800, neubyr wrote:
> On Sat, Dec 13, 2014 at 12:00 AM, Francis Daly <francis@daoine.org> wrote:
> > On Fri, Dec 12, 2014 at 04:00:29PM -0800, neubyr wrote:

Hi there,

> > > location /test {
> > > root /usr/share/nginx/test;
> > > }
> > >
> > > location /test/ {
> > > root /usr/share/nginx/test-slash;
> > > try_files $uri default.txt;
> > > }

> > 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)

Those questions still need answers, if you want someone else to be able
to tell you how to configure nginx to do your non-standard thing. (If
such a thing is even possible without extra coding.)

The "standard" thing is: requests that map directly to the filesystem
that match a directory that omit a trailing slash get a http 301 response
to include the trailing slash. That is usually what is wanted.

If you want something else, you'll have to be very clear about what it
is that you want.

The machine will do exactly what you configure it to do, not what you
hope it will do.

> 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.

I'm not sure why you expected a 404 if a non-slash request names an
existing directory by default. That's not the common thing to want.

You can get that by using (for example)

try_files $uri =404;

but that probably will not do what you want if the request *does* end
in a slash.

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

One request is handled in one location.

Depending on what actual configuration you used, the "/test/" url might
count as a new subrequest and start a new location search, or it
might not. See the documentation for whatever directive you are using
(explicitly or implicitly.)

For example using,

try_files $uri $uri/index.html =404;

in both /test and /test/ locations, a request for /test would send you
the contents of the file

/usr/share/nginx/test/test/index.html

if it exists (unless other configuration says not to), while a request
for /test/ would send you the contents of the file

/usr/share/nginx/test-slash/test/index.html

if it exists.

(Your "try_files $uri default.txt;" is unlikely to give you a useful result.)

Good luck with it,

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

stop automatic trailing slash addition

neubyr December 12, 2014 07:02PM

Re: stop automatic trailing slash addition

Edho Arief December 12, 2014 09:04PM

Re: stop automatic trailing slash addition

Francis Daly December 13, 2014 03:02AM

Re: stop automatic trailing slash addition

neubyr December 13, 2014 06:54PM

Re: stop automatic trailing slash addition

Valentin V. Bartenev December 13, 2014 07:28PM

Re: stop automatic trailing slash addition

neubyr December 14, 2014 02:40AM

Re: stop automatic trailing slash addition

Francis Daly December 14, 2014 05:54AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 191
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready