Nginx(4):nginx目录保护与IP访问

nginx访问目录保护

1、在需要保护的虚拟主机server标签内建立location标签并添加一下代码

        location /nginx_status{
           stub_status on;
           access_log off;
           auth_basic "Welcome to nginx_status";
           auth_basic_user_file /usr/local/nginx/html/htpasswd.nginx;
           allow 172.16.31.10
           deny 172.16.31.0/24
        }

2、安装含有htpasswd命令的包

yum provides "/*/htpasswd"
yum install -y httpd-tools-2.4.6-90.el7.centos.x86_64

3、使用htpasswd命令进行用户密码文件的创建
htpasswd -c /usr/local/nginx/html/htpasswd.nginx user

4、重启nginx并再次访问

service nginx reload

猜你喜欢

转载自blog.csdn.net/qq_40836555/article/details/105871652