赞
踩
https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
[root@localhost ~]# yum install httpd-tools -y
完毕!
[root@localhost ~]# htpasswd -b -c /etc/nginx/auth-passwd xp xp666
-c 创建passwdfile ,如果passwdfile文件已经存在,那么他就会重新写入,并删除原有的内容
-b 命令行中一并输入用户和密码,而不是根据提示去输入用户密码 可以看见是明文,并不需要去交互
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 你的密码文件
[root@localhost ~]# systemctl restart nginx
$ htpasswd -D /usr/local/nginx/password username
# -D 删除指定的用户
$ htpasswd -D /usr/local/nginx/password username
$ htpasswd -b /usr/local/nginx/password username pass
# -D 删除指定的用户
# -b htpassswd命令行中一并输入用户名和密码而不是根据提示输入密码
# -p htpassswd命令不对密码进行进行加密,即明文密码
server { listen 80; server_name example.com; location / { if ($http_user_agent ~* (PC|Windows|Macintosh)) { return 403; } # 蜘蛛的用户dai理字符串,可以根据需要进行修改 set $spider_user_agent "Googlebot"; if ($http_user_agent ~* $spider_user_agent) { # 对蜘蛛开放的代码 # 可以根据需要添加相应的重定向或dai理设置 } else { # 普通用户的代码 # 可以根据需要添加相应的重定向或dai理设置 } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。