student-manage/config/nginx/entrypoint.sh

25 lines
951 B
Bash
Raw Normal View History

2025-02-22 22:06:44 +08:00
#!/bin/sh
# 处理所有 .template 结尾的文件
for template in /etc/nginx/conf.d/*.template; do
[ ! -f "$template" ] && echo "No template files found" && continue
# 将输出文件名改为 .conf 结尾
conf="${template%.template}.conf"
echo "Processing $template"
if envsubst '$SERVER_IP' < "$template" > "$conf"; then
echo "Replaced $conf successfully"
else
echo "Failed to replace $conf"
fi
done
# Check if the index.html file exists before processing
if [ -f "/usr/share/nginx/html/index.html" ]; then
# Use envsubst to replace environment variable placeholders
2025-05-13 15:58:47 +08:00
envsubst < /usr/share/nginx/html/index.template > /usr/share/nginx/html/index.html.tmp
2025-02-22 22:06:44 +08:00
mv /usr/share/nginx/html/index.html.tmp /usr/share/nginx/html/index.html
else
echo "Info: /usr/share/nginx/html/index.html does not exist , skip replace env"
exit 1
fi
# Run nginx to serve static files
exec nginx -g "daemon off;"