Nginx訪問控制
進入Nginx配置文件
限制只讓某個IP訪問,加如下配置:
allow 192.168.1.101;
deny all;
禁止某個IP或者IP段訪問站點的設置方法,首先建立下面的配置文件放在Nginx的conf目錄下面,命名爲deny.ip
cat deny.ip
deny 192.168.1.11;
deny 192.168.1.123;
deny 10.1.0.24;
在對應的虛擬主機配置文件中加入:
include deny.ip;
重啓一下Nginx服務:
#/usr/local/nginx /sbin/nginx reload
deny.ip的格式中也可以用deny.all;
如果你想實現這樣的應用,撤了幾個IP外,其他全部拒絕,那就需要在deny.ip中這樣寫:
allow 1.1.1.1;
allow 1.1.1.2;
deny all;
有時候會根據目錄來限制PHP解析:
location ~.*(diy|template|p_w_uploads|forumdata|p_w_upload|p_w_picpath)/.*\.php$
{
deny all;
}