shell > yum -y install httpd-tools # 安装 htpasswd 工具 shell > cd /etc/nginx/conf.d shell > htpasswd -c /etc/nginx/cert/pass.db wang # 创建认证用户 wang 并输入密码,添加用户时输入 htpasswd pass.db username
shell > vim /etc/nginx/conf.d/local.conf server { listen 80; server_name local.server.com; auth_basic "User Authentication"; auth_basic_user_file /etc/nginx/cert/pass.db; location / { root /data/www; index index.html; } }