Nginx block all request except GET.
If you want to block a specific type of HTTP request methods like POST, then use limit_except
directive.
Edit your /etc/nginx/sites-enabled/<your-app>
location ~* {
limit_except GET {
allow 192.168.1.0/32;
deny all;
}
}
Restart your server:
sudo service nginx restart
If the restart fails, then you might have made a syntax error in your nginx configuration. After a successful restart, you will start receiving 403 responses for all the requests except GET/HEAD.
<html>
<head>
<title>403 Forbidden</title>
</head>
<body bgcolor="white">
<center>
<h1>403 Forbidden</h1>
</center>
<hr>
<center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>
Keep in mind,limit_except
is required to be declared inside a location directive.