Welcome! Log In Create A New Profile

Advanced

Re: Don't process requests containing folders

Francis Daly
September 12, 2016 05:50PM
On Mon, Sep 12, 2016 at 01:55:35PM -0700, Grant wrote:

Hi there,

> > If you want to match "requests with a second slash", do just that:
> >
> > location ~ ^/.*/ {}
> >
> > (the "^" is not necessary there, but I guess-without-testing that
> > it helps.)
>
> When you say it helps, you mean for performance?

Yes - I guess that anchoring this regex at a point where it will always
match anyway, will do no harm.

> > If you want to match "requests without a second slash", you could do
> >
> > location ~ ^/[^/]*$ {}
> >
> > but I suspect you'll be better off with the positive match, plus a
> > "location /" for "all the rest".
>
>
> I want to keep my location blocks to a minimum so I think I should use
> the following as my last location block which will send all remaining
> good requests to my backend:
>
> location ~ (^/[^/]*|.html)$ {}

Yes, that should do what you describe.

Note that the . is a metacharacter for "any one"; if you really want
the five-character string ".html" at the end of the request, you should
escape the . to \.

> And let everything else match the following, most of which will 404 (cheaply):
>
> location / { internal; }

Testing and measuring might show that "return 404;" is even cheaper than
"internal;" in the cases where they have the same output. But if there
are cases where the difference in output matters, or if the difference
is not measurable, then leaving it as-is is fine.

Cheers,

f
--
Francis Daly francis@daoine.org

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

Don't process requests containing folders

Grant September 12, 2016 01:18PM

Re: Don't process requests containing folders

Francis Daly September 12, 2016 04:28PM

Re: Don't process requests containing folders

Grant September 12, 2016 04:58PM

Re: Don't process requests containing folders

Francis Daly September 12, 2016 05:50PM

Re: Don't process requests containing folders

Grant September 12, 2016 07:34PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 202
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