@@ -75,7 +75,6 @@ while true; do
75
75
DEST_VAR=" ROUTE_${i} _DESTINATION"
76
76
PORT_VAR=" ROUTE_${i} _PORT"
77
77
78
- # Stop if no more routes
79
78
[ -z " ${! HOST_VAR} " ] && break
80
79
81
80
ROUTE_HOST=" ${! HOST_VAR} "
@@ -89,7 +88,7 @@ while true; do
89
88
proxy_pass http://${ROUTE_DEST} :${ROUTE_PORT} ;
90
89
proxy_http_version 1.1;
91
90
proxy_set_header Upgrade \$ http_upgrade;
92
- proxy_set_header Connection \" upgrade\" ;
91
+ proxy_set_header Connection \" upgrade\" ;
93
92
proxy_set_header Host \$ host;
94
93
proxy_set_header X-Real-IP \$ remote_addr;
95
94
proxy_set_header X-Forwarded-For \$ proxy_add_x_forwarded_for;
@@ -111,21 +110,17 @@ ${SERVER_BLOCKS[$HOST]}
111
110
}"
112
111
done
113
112
114
- # Process template and inject dynamic blocks
115
113
log " Generating Nginx configuration..."
116
- export DYNAMIC_SERVER_BLOCKS
117
-
118
- envsubst ' ${NGINX_PORT} ${PROXY_PASS_DEFAULT} ${PROXY_PORT_DEFAULT} ${ADDITIONAL_ROUTES}' \
119
- < /etc/nginx/templates/nginx.conf.template > /etc/nginx/nginx.conf.tmp
120
-
121
- # Inject dynamic server blocks before closing HTTP block
122
- # Escape slashes, backslashes, and ampersands
123
- ESCAPED_BLOCKS=$( echo " ${DYNAMIC_SERVER_BLOCKS} " | sed -e ' s/[\/&]/\\&/g' )
124
114
125
- # Inject into nginx.conf
126
- sed -i " /^}$/i ${ESCAPED_BLOCKS} " /etc/nginx/nginx.conf.tmp
127
-
128
- mv /etc/nginx/nginx.conf.tmp /etc/nginx/nginx.conf
115
+ export DYNAMIC_SERVER_BLOCKS
116
+ export ADDITIONAL_ROUTES
117
+ export NGINX_PORT
118
+ export PROXY_PASS_DEFAULT
119
+ export PROXY_PORT_DEFAULT
120
+
121
+ # Use envsubst to replace the markers
122
+ envsubst ' ${NGINX_PORT} ${PROXY_PASS_DEFAULT} ${PROXY_PORT_DEFAULT} ${ADDITIONAL_ROUTES} ${DYNAMIC_SERVER_BLOCKS}' \
123
+ < /etc/nginx/templates/nginx.conf.template > /etc/nginx/nginx.conf
129
124
130
125
log " Final Nginx configuration:"
131
126
cat /etc/nginx/nginx.conf
0 commit comments