nginx改为模板配置,从环境变量文件中读取并替换

This commit is contained in:
david_bai
2025-05-17 17:31:08 +08:00
parent d56f6b5383
commit 4b0a8049a7
3 changed files with 5 additions and 75 deletions
-5
View File
@@ -1,5 +0,0 @@
cp default /etc/nginx/sites-available/
cp nginx.conf /etc/nginx
nginx -t
/etc/init.d/nginx restart
+5 -5
View File
@@ -1,7 +1,7 @@
server {
# 将 HTTP 重定向到 HTTPS
listen 80;
server_name securityshare.xyz www.securityshare.xyz;
server_name YourDomain www.YourDomain;
return 301 https://$server_name$request_uri;
}
@@ -23,11 +23,11 @@ server {
# 需要客户端和服务器都支持
ssl_early_data on;
server_name securityshare.xyz www.securityshare.xyz;
server_name YourDomain www.YourDomain;
# SSL 配置
ssl_certificate /etc/letsencrypt/live/securityshare.xyz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/securityshare.xyz/privkey.pem;
ssl_certificate path/to/your/certFile;
ssl_certificate_key path/to/your/privkeyFile;
# SSL 优化
ssl_session_timeout 1d;
@@ -43,7 +43,7 @@ server {
# 定义前端构建产物在容器内的根路径
# !!! 重要: 请将此路径修改为您的前端项目构建后在Nginx容器内的实际路径 !!!
set $frontend_build_root /home/ubuntu/workdir_atbj/clipboard_web;
set $frontend_build_root path/to/your/frontend_build_root;
# 1. 优先处理 Next.js 的核心静态资源 (_next/static)
location /_next/static/ {
-65
View File
@@ -1,65 +0,0 @@
#!/bin/bash
# 检查参数
if [ -z "$1" ]; then
echo "Usage: $0 <env_file_path>"
exit 1
fi
ENV_FILE=$1
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 检查环境变量文件是否存在
if [ ! -f "$ENV_FILE" ]; then
echo "Error: Environment file $ENV_FILE not found"
exit 1
fi
# 读取环境变量
source "$ENV_FILE"
echo "Configuring TURN server..."
# 确定使用哪个配置模板
if [[ "$NODE_ENV" == "development" ]]; then
TEMPLATE_FILE="$SCRIPT_DIR/turnserver_development.conf"
else
TEMPLATE_FILE="$SCRIPT_DIR/turnserver_production.conf"
fi
# 创建临时配置文件
TEMP_CONF=$(mktemp)
# 读取模板并替换变量
while IFS= read -r line || [ -n "$line" ]; do
# 替换external-ip
if [[ $line =~ ^external-ip= ]]; then
echo "external-ip=$TURN_EXTERNAL_IP"
# 替换realm
elif [[ $line =~ ^realm= ]]; then
echo "realm=$TURN_REALM"
# 替换user credentials
elif [[ $line =~ ^user= ]]; then
echo "user=$TURN_USERNAME:$TURN_PASSWORD"
# 替换证书路径
elif [[ $line =~ ^cert= ]]; then
echo "cert=$TURN_CERT_PATH"
# 替换密钥路径
elif [[ $line =~ ^pkey= ]]; then
echo "pkey=$TURN_KEY_PATH"
else
echo "$line"
fi
done < "$TEMPLATE_FILE" > "$TEMP_CONF"
# cp "$TEMP_CONF" turnserver.conf
# 使用sudo复制配置文件到目标位置
cp "$TEMP_CONF" /etc/turnserver.conf
# # 删除临时文件
rm "$TEMP_CONF"
# # 重启TURN服务器
service coturn restart
echo "TURN server configuration has been updated and service restarted."