-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-auth.sh
More file actions
executable file
·25 lines (23 loc) · 1 KB
/
setup-auth.sh
File metadata and controls
executable file
·25 lines (23 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
set -e
# 设置基本认证
if [ -n "$BASIC_AUTH_USER" ] && [ -n "$BASIC_AUTH_PASSWORD" ]; then
echo "Setting up basic authentication for user: $BASIC_AUTH_USER"
# 创建 htpasswd 文件
htpasswd -b -c /etc/nginx/auth/.htpasswd "$BASIC_AUTH_USER" "$BASIC_AUTH_PASSWORD" 2>/dev/null || \
# 如果 htpasswd 不可用,使用 openssl 替代
{
echo "Using openssl as fallback for password generation"
echo "$BASIC_AUTH_USER:$(openssl passwd -apr1 $BASIC_AUTH_PASSWORD)" > /etc/nginx/auth/.htpasswd
}
echo "Basic authentication configured"
else
echo "WARNING: BASIC_AUTH_USER or BASIC_AUTH_PASSWORD not set, disabling authentication"
# 禁用 nginx 认证
sed -i 's/auth_basic/# auth_basic/g' /etc/nginx/conf.d/default.conf
sed -i 's/auth_basic_user_file/# auth_basic_user_file/g' /etc/nginx/conf.d/default.conf
fi
# 设置 NOTE_STORAGE_PATH 环境变量(如果需要传递给应用)
if [ -n "$NOTE_STORAGE_PATH" ]; then
export NOTE_STORAGE_PATH
fi