Skip to content

Commit

Permalink
增加 Nginx 配置 Basic Auth 认证笔记。
Browse files Browse the repository at this point in the history
  • Loading branch information
Suomea committed Dec 6, 2024
1 parent 32e930a commit eb41213
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/Linux/Nginx 配置 Basic Auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
首先使用 openssl 获取加密密码 openssl passwd -5 your-password,比如密码 123456。
```
# openssl passwd -5 123456
$5$jZFBH2tXARpLGmik$YDeK49P73WVVYzfjhWVZG7ZjHXyc7g0MVaWCZXHc0U9
```

然后新增配置文件 conf/.htpasswd。
```
usera:$5$jZFBH2tXARpLGmik$YDeK49P73WVVYzfjhWVZG7ZjHXyc7g0MVaWCZXHc0U9
userb:$5$jZFBH2tXARpLGmik$YDeK49P73WVVYzfjhWVZG7ZjHXyc7g0MVaWCZXHc0U9
```

编辑 Nginx 配置文件。
```
server {
listen 80;
server_name localhost;
auth_basic "Restricted Access"; # 设置提示信息
auth_basic_user_file ./.htpasswd; # 指定认证文件路径
location / {
root html;
index index.html index.htm;
}
}
```

配置文件生效之后,访问主机的 80 端口,使用 usera/123456 和 userb/123456 都能进行访问。

0 comments on commit eb41213

Please sign in to comment.