语法:
#开启认证控制,没有任何作用就是为了开启
Syntax: auth_basic string | off;
Default: auth_basic off;
Context: http, server, location, limit_except
#指定用户认证的文件
Syntax: auth_basic_user_file file;
Default: —
Context: http, server, location, limit_except
[root@web02 /etc/nginx/conf.d]# htpasswd -c /etc/nginx/auth_basic clf
[root@web02 /etc/nginx/conf.d]# cat /etc/nginx/auth_basic
[root@web02 ]# vim /etc/nginx/conf.d/test.conf
server { listen 80; server_name www.test.com; charset utf-8; location / { root /code; index index.html; } location /download { root /code; index index.html; autoindex on; autoindex_exact_size off; autoindex_localtime on; allow 10.0.0.1; deny all; auth_basic on; auth_basic_user_file /etc/nginx/auth_basic; } }