版权声明:silly8543 https://blog.csdn.net/cen50958/article/details/89684935
用户在访问时,需要先输入账户和密码,认证通过后才可以访问网站信息,主要用于企业内部人员访问的地址
- 官方文档地址
http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
-
server配置
location / { auth_basic "study site"; auth_basic_user_file /application/nginx/conf/htpasswd; root html; index index.html index.htm; }
-
生成密码文件
安装httpd-tools工具yum install httpd-tools -y
检查是否安装htpasswd
[root@study conf]# rpm -qf /usr/bin/htpasswd
httpd-tools-2.2.15-69.el6.centos.x86_64生成htpasswd文件
htpasswd -cb /application/nginx/conf/htpasswd silly 123456 //用户名:silly 密码:123456 会创建文件,原来生成的会被清掉,只有silly用户 htpasswd -b /application/nginx/conf/htpasswd silly8543 123456 //在原有的文件中新增用户 silly8543
设置htpasswd权限chmod 400 /application/nginx/conf/htpasswd
htpasswd具体用法可参考博文:
-
重新加载配置文件
/application/nginx/sbin/nginx -s reload