Nginx访问控制

nginx访问控制
禁止一些非法的IP进行访问,允许某些IP访问
修改虚拟主机配置文件
[root@wqslinux ~]# vim /usr/local/nginx/conf/vhosts/111.conf

server
{
listen 80;
server_name www.111.com www.bbb.com;
if ($host != “www.111.com”)
{
rewrite ^/(.*)$ http://www.111.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www/;
allow192.168.205.1; //全局配置白名单允许访问,注意加deny all
deny all;
deny192.168.205.0/24; //设置黑名单的网段,就deny就可以
access_log /tmp/access.log wqs;
location ~ .*forum.php$ {
allow 127.0.0.1; //局部限制allow允许访问
deny all; //deny 限制访问
#auth_basic “user auth”;
#auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
检查语法是否有问题
[root@wqslinux ~]#/usr/local/nginx/sbin/nginx -t
重新加载
[root@wqslinux ~]#/usr/local/nginx/sbin/nginx -s reload

发表评论