Nginx可以禁止某些IP或者只允许某些IP对网站进行访问,这样的做法比用户认证的方式更加方便和安全。
比如针对/admin.php添加白名单,只允许本机对该admin.php结尾的URL进行访问,但是不能访问整站。
# vim /usr/local/nginx/conf/vhosts/test.conf
server
{
listen 80;
server_name ;
index index.html index.htm index.php;
root /data/test;
deny 192.168.176.129; //黑名单
location ~ .*admin\.php$ {
allow 127.0.0.1; //白名单
deny all;
}
}