咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

nginx开启用户授权

有时候有些静态网站:如文档类的,放在公网,希望要用户认证才能访问,Nginx的
ngx_http_auth_basic_module 模块基于 “HTTP Basic Authentication” 协议实现了用户认证,可以很方便的实现用户认证。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
listen 80;
server_name localhost;

# 随便填些信息都行
# auth_basic off 关闭用户授权
auth_basic "welcome";
# 授权信息路径
auth_basic_user_file /etc/auth_basic/userpasswd;

location / {
root /var/www/test;
index index.html;
}
}

userpasswd 这个文件的一行代表一个用户,格式是: user:passwd ,其中密码是加密的,可以通过 htpasswd 工具来生成。

1
2
3
4
$ htpasswd -cb ./userpasswd test 123456
Adding password for user test
$ cat userpasswd
test:$apr1$2fZNNVc7$/w76Ek8aezH7g1WoLgtx5/

** 浏览器授权访问 **

** postman授权访问 **

** postman访问密码错误 **