@@ -122,6 +122,48 @@ export PROXY_PORT_DEFAULT
122
122
envsubst ' ${NGINX_PORT} ${PROXY_PASS_DEFAULT} ${PROXY_PORT_DEFAULT} ${ADDITIONAL_ROUTES} ${DYNAMIC_SERVER_BLOCKS}' \
123
123
< /etc/nginx/templates/nginx.conf.template > /etc/nginx/nginx.conf
124
124
125
+
126
+ # --- Dynamic Stream (TCP) Proxy Configuration ---
127
+ log " Generating TCP stream proxy configuration..."
128
+
129
+ STREAM_SERVER_BLOCKS=" "
130
+ k=1
131
+ while true ; do
132
+ STREAM_HOST_VAR=" STREAM_ROUTE_${k} _DESTINATION"
133
+ STREAM_PORT_VAR=" STREAM_ROUTE_${k} _PORT"
134
+ STREAM_LISTEN_VAR=" STREAM_ROUTE_${k} _LISTEN_PORT"
135
+ STREAM_PROXY_PROTOCOL_VAR=" STREAM_ROUTE_${k} _PROXY_PROTOCOL"
136
+
137
+ [ -z " ${! STREAM_HOST_VAR} " ] && break
138
+
139
+ STREAM_DEST=" ${! STREAM_HOST_VAR} "
140
+ STREAM_PORT=" ${! STREAM_PORT_VAR:- 80} "
141
+ STREAM_LISTEN=" ${! STREAM_LISTEN_VAR:- $STREAM_PORT } " # Default listen = destination port
142
+ STREAM_PROXY_PROTOCOL=" ${! STREAM_PROXY_PROTOCOL_VAR:- off} "
143
+
144
+ log " Adding stream route: 0.0.0.0:$STREAM_LISTEN -> $STREAM_DEST :$STREAM_PORT (proxy_protocol=$STREAM_PROXY_PROTOCOL )"
145
+
146
+ STREAM_SERVER_BLOCKS+="
147
+ server {
148
+ listen ${STREAM_LISTEN} ;
149
+ proxy_pass ${STREAM_DEST} :${STREAM_PORT} ;
150
+ proxy_protocol ${STREAM_PROXY_PROTOCOL} ;
151
+ }
152
+ "
153
+ k=$(( k+ 1 ))
154
+ done
155
+
156
+ if [ -n " $STREAM_SERVER_BLOCKS " ]; then
157
+ cat << EOF > /etc/nginx/nginx.stream.conf
158
+ stream {
159
+ $STREAM_SERVER_BLOCKS
160
+ }
161
+ EOF
162
+ else
163
+ log " No TCP stream routes defined."
164
+ fi
165
+
166
+
125
167
log " Final Nginx configuration:"
126
168
cat /etc/nginx/nginx.conf
127
169
0 commit comments