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

Is it possible in the nginx.conf file to limit incoming POST requests to just a few pages?

Say I only want to allow post requests on signup.php and login.php but not on all other possible pages.

Reason why I ask is that my server often gets flooded with POST requests on random pages, which causes unnecessary load.

I tried blocking it in PHP, but in this case nginx still has to process and accept the full POST data. This i'm trying to prevent.

share|improve this question
up vote 2 down vote accepted

You'll need to create multiple locations to handle the different situations:

# including your fastcgi params at a higher level
# allows them to be inherited in both locations
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;

# regex locations are matched in order, so this will handle
# /anything/signup.php and /anything/login.php
# If you want to just have /signup.php and /login.php,
# add ^ before the / or you could split this into two more:
# location = /signup.php abd location = /login.php
location ~ /(signup|login)\.php$ {
  fastcgi_pass php;

# this will handle the rest of the php requests
location ~ \.php$ {
  # Only allow GET and HEAD requests for all other php scripts
  limit_except GET HEAD {
     allow; #trusted ip
     deny all;
  fastcgi_pass php;
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.