用于location段
allow:设定允许哪台或哪些主机访问,多个参数间用空格隔开
deny:设定禁止哪台或哪些主机访问,多个参数间用空格隔开
示例:
allow 192.168.170.132/32 192.168.170.133/32; deny all;
拒绝本机访问nginx状态页面
location /status { stub_status on; deny 192.168.170.1; }
auth_basic "欢迎信息"; auth_basic_user_file "/path/to/user_auth_file" //user_auth_file内容格式 username:password
这里的密码为加密后的密码串,建议用htpasswd来创建此文件:
htpasswd -c -m /path/to/.user_auth_file USERNAME
授权用户
[root@localhost ssl]# yum install -y httpd-tools //tom账户要之前没有创建的 [root@localhost conf]# htpasswd -c -m .user_auth_file tom New password: Re-type new password: Adding password for user tom [root@localhost conf]# ls -a | grep .user_auth_file .user_auth_file [root@localhost conf]# cat .user_auth_file tom:$apr1$OhUzbIS3$f1MpCShCyvCYtMUIn6BMD1
配置(必须要用绝对路径)
[root@localhost conf]# vim nginx.conf location /status { stub_status on; auth_basic "欢迎查看"; auth_basic_user_file "/usr/local/nginx/conf/.user_auth_file"; } [root@localhost conf]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@localhost conf]# nginx -s reload
原文:https://www.cnblogs.com/meijianbiao/p/14833600.html