Nginx访问控制
一、黑(白)名单
[root@web-nginx conf.d]# vim access-control.conf
server {
listen 80;
server_name www.access-control.com;
access_log /var/log/nginx/access-control-access.log main;
error_log /var/log/nginx/access-control-error.log;
location /{
root /var/www/access;
index index.php index.htm index.html;
}
#设置白名单访问/status页面
location /status{
allow 192.168.133.0/24;
deny all;
stub_status on;
access_log off;
}
}
二、账号访问
[root@web-nginx conf.d]# yum -y install httpd-tools
[root@web-nginx conf.d]# htpasswd -c /var/www/auth_conf test
password:
[root@web-nginx conf.d]# vim access-control.conf
server {
listen 80;
server_name www.access-control.com;
access_log /var/log/nginx/access-control-access.log main;
error_log /var/log/nginx/access-control-error.log;
location /{
root /var/www/access;
index index.php index.htm index.html;
}
#指定页面设置账号访问
location = /xxx.html{
auth_basic "input user,password!";
auth_basic_user_file /var/www/auth_conf;
index index.html index.htm;
}
}
Nginx访问控制