1

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?

0

1 Answer 1

3

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;
            }
Sign up to request clarification or add additional context in comments.

3 Comments

How to redirected the disallowed methods to another proxy_pass?
@W.M. You can redirect using if verb, if ($request_method = POST ) { return 301 https://example.com$request_uri; }
For clarity, as I've just had the same problem, this limits EVERYTHING BUT GET. i.e. <ip subnet 1> will be allowed on POST, PUT, etc, but nothing else will. Everything will be allowed GET requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.