1.修改配置文件
[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf .. .. server { listen 80; server_name localhost; auth_basic "Input Password:"; //认证提示符 auth_basic_user_file "/usr/local/nginx/pass"; //认证密码文件 location / { root html; index index.html index.htm; } }
2.生成密码文件、创建认证用户及密码
[root@proxy ~]# yum -y install httpd-tools [root@proxy ~]# htpasswd -c /usr/local/nginx/pass tom //创建密码文件 New password: Re-type new password: Adding password for user tom [root@proxy ~]# htpasswd /usr/local/nginx/pass jerry //追加用户,不使用-c选项 New password: Re-type new password: Adding password for user jerry
3.重启服务
[root@proxy ~]# /usr/local/nginx/sbin/nginx -s reload //重新加载配置文件 # nginx -s reload