Last active
October 13, 2025 14:43
-
-
Save arubis/247f62e40acebeefd989b89dc5cf6da5 to your computer and use it in GitHub Desktop.
Nginx userspace proxy script - expose localhost service on interface IPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Create temporary nginx config | |
| CONF_FILE=$(mktemp) | |
| trap "rm -f $CONF_FILE" EXIT | |
| cat > "$CONF_FILE" << 'EOF' | |
| pid /tmp/nginx.pid; | |
| error_log /tmp/nginx-error.log; | |
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| access_log /tmp/nginx-access.log; | |
| client_body_temp_path /tmp/nginx-client-body; | |
| proxy_temp_path /tmp/nginx-proxy; | |
| fastcgi_temp_path /tmp/nginx-fastcgi; | |
| uwsgi_temp_path /tmp/nginx-uwsgi; | |
| scgi_temp_path /tmp/nginx-scgi; | |
| # WebSocket connection upgrade mapping | |
| map $http_upgrade $connection_upgrade { | |
| default upgrade; | |
| '' close; | |
| } | |
| upstream backend { | |
| server 127.0.0.1:9090; | |
| } | |
| server { | |
| listen 10.5.0.5:9080; | |
| listen 100.79.106.85:9080; | |
| location / { | |
| proxy_pass http://backend; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X-Forwarded-Proto $scheme; | |
| # WebSocket support | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection $connection_upgrade; | |
| proxy_cache_bypass $http_upgrade; | |
| } | |
| } | |
| } | |
| EOF | |
| echo "Starting nginx proxy: localhost:9090 -> 10.5.0.5:9080, 100.79.106.85:9080" | |
| echo "Press Ctrl+C to stop" | |
| nginx -c "$CONF_FILE" -g 'daemon off;' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment