2017-02-28 80 views
1

Nginx configs提供了完全新的Noob。我想基于IP限制HTTP请求:这里是我到目前为止:我需要让所有的GET,但是我需要限制PUT DELETE和POST到特定IP范围在Nginx中限制http请求

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; 
      } 

任何想法,我会出错吗?它甚至有可能吗?

回答

2

以下将拒绝除GETHEAD以外的所有方法。如果客户端来自指定的IP范围,则它将有权访问其他方法。

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; 
      } 
+0

如何将不允许的方法重定向到另一个'proxy_pass'? –

+0

@ W.M。您可以使用if动词来重定向,如果($ request_method = POST){ return 301 https://example.com$request_uri; }' –

+1

为了清楚起见,我刚刚遇到同样的问题,这限制了一切,但限制了GET。即将被允许在POST,PUT等上,但没有别的。一切都会被允许GET请求。 –