发布时间:2020-03-06 10:57:03编辑:admin阅读(3248)
在实际工作中,企业中有些网站,要求使用账号和密码才能访问,如网站后台、phpMyAdmin 、Wiki 平台 等
模块ngx_http_auth_basic_module 允许使用“HTTP基本认证”协议验证用户名和密码来限制对资源的访问
模块ngx_http_auth_basic_module 下有两条指令 auth_basic 和 auth_basic_user_file
Centos 6.9
wget https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm rpm -ivh epel-release-latest-6.noarch.rpm
yum intall -y nginx
yum install -y httpd-tools htpasswd -bc /etc/nginx/conf.d/htpasswd.users username password
注意:username和password,分别对应用名和密码
创建新的配置
vi /etc/nginx/conf.d/browse.conf
内容如下:
server {
listen 81;
server_name localhost;
location / {
root /data/log/tomcat;
index index.html index.htm;
# 设置用于认证的提示字符串
auth_basic "Restricted Access";
# 设置认证的密码文件
auth_basic_user_file /etc/nginx/conf.d/htpasswd.users;
#自动显示目录
autoindex on;
#改为off后,显示出文件的大概大小,单位是kB或者MB或者GB;即人性化方式显示文件大小否则以byte显示
autoindex_exact_size off;
autoindex_localtime on;
}
}
nginx -s reload
输入用户名和密码
效果如下:
文本参考链接:
https://www.cnblogs.com/wushuaishuai/p/9361811.html
https://blog.csdn.net/haigenwong/article/details/84477218
https://www.cnblogs.com/silent2012/p/8377837.html
下一篇: CentOS7 docker安装
51551
51114
41648
38403
32890
29869
28583
23538
23471
21821
1967°
2669°
2222°
2158°
2607°
2187°
2916°
4841°
4683°
3326°