Welcome! Log In Create A New Profile

Advanced

Re: Nginx location - Distinguish requests by arguments or queries

Francis Daly
February 25, 2020 12:08PM
On Tue, Feb 25, 2020 at 07:05:05AM -0500, stmx38 wrote:

Hi there,

> We have a case when we should permit different methods on the same location
> but different requests.

The nginx model does "location" matching without reference to the
query string.

But you may be able to build your own "good-enough" config, for your
use case.

> For location /test we should permit only POST, for /test?doc we should
> permit only GET methods.

As you have seen - limit_except does not do what you want.

But if you can enumerate the things that you want to allow (or: want
to block), then you can make your own variable from "method" and "uri"
that you can test. Only checking it within the one location{} should
reduce the impact on any other requests.

If you change the list of things that should be allowed, then you will
need ongoing maintenance of the hardcoded list.

Something like:

==
map $request_method$request_uri $block_this {
default 1;
~*GET/test\?doc 0;
~*POST/test\?. 1;
~*POST/test 0;
}
==

along with

==
location /test {
error_page 403 =405 /custom-error;
if ($block_this = 1) { return 403; }
proxy_pass http://test/in;
}
==

(Set the return code to what you want.)

may be adaptable to do what you want.

The case-insensitive is because I don't know if your clients do GET or get
or gEt; and I don't know how important it is that *no* "should-be-blocked"
requests get to your back-end. Adjust to taste based on testing.

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

Nginx location - Distinguish requests by arguments or queries

stmx38 February 25, 2020 07:05AM

Re: Nginx location - Distinguish requests by arguments or queries

Francis Daly February 25, 2020 12:08PM

Re: Nginx location - Distinguish requests by arguments or queries

Francis Daly February 26, 2020 03:50AM

Re: Nginx location - Distinguish requests by arguments or queries

stmx38 February 27, 2020 02:20PM

Re: Nginx location - Distinguish requests by arguments or queries

Francis Daly February 27, 2020 06:32PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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