training_data/config/nginx/entrypoint.sh

28 lines
1.1 KiB
Bash
Raw Normal View History

2025-01-03 09:24:46 +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"
2025-02-24 08:51:44 +08:00
if envsubst '$SERVER_IP $SERVER_PORT' < "$template" > "$conf"; then
2025-01-03 09:24:46 +08:00
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-03-05 09:17:36 +08:00
echo "Processing /usr/share/nginx/html/index.html"
envsubst < /usr/share/nginx/html/index.template > /usr/share/nginx/html/index.html.tmp
2025-01-03 09:24:46 +08:00
mv /usr/share/nginx/html/index.html.tmp /usr/share/nginx/html/index.html
2025-03-05 09:17:36 +08:00
echo "Processed content:"
cat /usr/share/nginx/html/index.html
2025-01-03 09:24:46 +08:00
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;"