[root@nginx1 ~]# 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;
} }
[root@nginx1 ~]#yum -y install httpd-tools
[root@nginx1 ~]#htpasswd -c /usr/local/nginx/pass tom \\输入密码
[root@nginx1 ~]# /sbin/nginx -s reload \\重启
访问测试输入账号密码