Noob
Noob

Reputation: 752

How to block a specific URL in NGINX webserver

I want to block a specific URL but I am not able to do this.

The URL that should be blocked is example.com/clientarea/?dxx_g=dddd. But the following url should still work - example.com/clientarea.

I tried the following:

location ^~ /clientarea/ {
  return 444;
}

But if I do this it will block all connections to /clientarea.

I hope you can help me or advise me how to make this possible.

Upvotes: 1

Views: 5980

Answers (1)

Richard Smith
Richard Smith

Reputation: 49822

The location and rewrite statements test a normalized URI which does not include the ? and anything following it.

The $request_uri variable contains the entire URI. Test this variable using an if or map directive.

For example:

if ($request_uri = /clientarea/?dxx_g=dddd) {
    return 444;
}

You can also use regular expressions. See this document for more. See this caution on the use of if.

If you have a number of URIs to block, you should consider using a map instead.

Upvotes: 1

Related Questions