Skip to content

Commit b3e1b65

Browse files
authored
TCP Stream support
1 parent e8a1bc5 commit b3e1b65

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

pritunl-nginx-proxy/entrypoint.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,48 @@ export PROXY_PORT_DEFAULT
122122
envsubst '${NGINX_PORT} ${PROXY_PASS_DEFAULT} ${PROXY_PORT_DEFAULT} ${ADDITIONAL_ROUTES} ${DYNAMIC_SERVER_BLOCKS}' \
123123
< /etc/nginx/templates/nginx.conf.template > /etc/nginx/nginx.conf
124124

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+
125167
log "Final Nginx configuration:"
126168
cat /etc/nginx/nginx.conf
127169

pritunl-nginx-proxy/nginx.conf.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ user www-data;
22
worker_processes auto;
33
pid /run/nginx.pid;
44
include /etc/nginx/modules-enabled/*.conf;
5+
include /etc/nginx/nginx.stream.conf;
56

67
events {
78
worker_connections 1024;

0 commit comments

Comments
 (0)