jping45
jping45

Reputation: 11

Limiting http request in Nginx

Completly new Noob with it comes to Nginx configs. I'm trying to limit http requests based on IP: Here's what I have so far: I need to allow all GETs, however I need to limit PUT DELETE and POST to specific IP Ranges

location / {
            index app.php index.php index.html;
            try_files $uri @rewriteapp;
            limit_except GET {
                    allow all;
            }
            limit_except PUT DELETE POST {
                    allow <IP SUBNET 1>;
                    allow <IP SUBNET 2>;
                    deny all;
            }

Any idea what I'm getting wrong? Is it even possible?

Upvotes: 1

Views: 4285

Answers (1)

Farhad Farahi
Farhad Farahi

Reputation: 39247

The following will reject every method except GET and HEAD. If the client is from specified ip ranges, it will have access to other methods.

location / {
            index app.php index.php index.html;
            try_files $uri @rewriteapp;

            limit_except GET {
                    allow <IP SUBNET 1>;
                    allow <IP SUBNET 2>;
                    deny all;
            }

Upvotes: 3

Related Questions