T
T
theodorheia2021-05-26 14:24:41
Nginx
theodorheia, 2021-05-26 14:24:41

How to reject URL requests in nginx that contain a get method?

The task is to reject all requests for a specific url.
url next - "/blablabla/bla?x=55&y=="
​​Everything seems to be simple, I create a location and deny all:
location = /blablabla/bla?x=55&y== {deny all;}
Then I check with curl:
curl -I ' localhost/blablabla/bla?x=55&y== '
I get 404, although I should get 403.
Also, if I put return 200 instead of deny all, I still get 404.

I know that I can do this:
location ~ /blablabla/bla {
if ( $args ~ ^x=55&y== ) { return 403; }
}
But at high loads, the conditional statement can take a lot of CPU.

Maybe I'm wrong in the syntax?
Or the only option is the second method?

Thanks for the help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-05-26
@Lynn

Second method. query parameters never match in location.
> But at high loads, the conditional statement can take a lot of CPU.
I strongly doubt that you have such high loads that it would be noticeable.
Well, in if, you can use a simple comparison, not a regular expression.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question