nginx设置用户密码

2023-12-04

1.官网

https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html

2.语法

在这里插入图片描述

3.创建密码

[root@localhost ~]# yum install httpd-tools -y

4.创建密码文件

完毕!
[root@localhost ~]# htpasswd -b -c /etc/nginx/auth-passwd xp xp666

-c 创建passwdfile ,如果passwdfile文件已经存在,那么他就会重新写入,并删除原有的内容
-b 命令行中一并输入用户和密码,而不是根据提示去输入用户密码 可以看见是明文,并不需要去交互

5.往配置文件中写入两行

server {
  listen 80;
  server_name 192.168.134.139;
  location / {
 auth_basic "please input your account password";
        auth_basic_user_file /etc/nginx/auth_passwd;
  root /www/xp;
  index index.html;
}
}

auto_bassic 是给用户看的提示
auto_basic_user_file 你的密码文件

6.重启nginx

[root@localhost ~]# systemctl restart nginx

7.再次访问

在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nginx设置用户密码 的相关文章

随机推荐