Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Looking to block any requests that contain the following strings in nginx


Just really looking to return like a 500 error or such.. Nothing fancy

share|improve this question
up vote 2 down vote accepted

I think a server-level if is what you need. If you want to search the whole request, including args, you should be able to use:

server {
  if ($request_uri ~ %0[adAD]) { return 500; }

If you just want to check the path part of the uri:

server {
  if ($uri ~ [\r\n]) { return 500; }

should do the job

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.