Skip to content

Add nginx layer 4 proxying#113

Merged
runleveldev merged 6 commits intomainfrom
55-nginx-reverse-proxy-add-nginx-layer-4-proxying
Nov 18, 2025
Merged

Add nginx layer 4 proxying#113
runleveldev merged 6 commits intomainfrom
55-nginx-reverse-proxy-add-nginx-layer-4-proxying

Conversation

@runleveldev
Copy link
Collaborator

@runleveldev runleveldev commented Nov 11, 2025

This pull request introduces several improvements to both the container registration workflow and the reverse proxy configuration system. The changes ensure more reliable port assignments, improve logging and debugging, and enhance the generated NGINX configuration to support both HTTP and stream (TCP/UDP) services. Key changes are grouped below.

Container registration and port assignment improvements:

  • Added a new method nextAvailablePortInRange to the Service model to reliably find the next available external port for a given protocol type, preventing port conflicts and improving scalability. This is now used for SSH and additional protocol port assignments instead of relying on iptables parsing. [1] [2] [3]
  • The container registration script (register-container.sh) now delegates port assignment to the API, removing local iptables-based port management logic. The assigned SSH port is extracted from the API response. [1] [2] [3]

Logging and debugging enhancements:

  • Added support for redirecting stdout and stderr to a log file in the registration script for better traceability. [1] [2]
  • Integrated the morgan HTTP request logger middleware into the Node.js server for improved request logging and debugging. [1] [2] [3] [4] [5] [6]

NGINX configuration improvements:

  • The generated NGINX configuration now includes both HTTP and stream (TCP/UDP) services, allowing for reverse proxying of various protocols. The configuration template was refactored to group and render services by type. [1] [2] [3]
  • The reverse proxy configuration script now fetches the main nginx.conf instead of a single site config, aligning with the new template structure.

API and environment flexibility:

  • The container registration script now allows overriding the API URL via an environment variable, making it easier to test against different endpoints.

Deployment:

API Server:

  1. git pull
  2. npm i
  3. systemctl restart container-creator.service

Load Balancer:

  1. git pull
  2. rm /etc/nginx/conf.d/reverse-proxy.conf*
  3. /opt/opensource-server/nginx-reverse-proxy/pull-config.sh

Proxmox Host:

  1. Pull the new register-container.sh to /var/lib/vz/snippets
  2. Flush the IPTables NAT rules

Firewall:

  1. Insert any custom, firewall-layer port forwards into the database for their relevant containers.
  2. NAT 80/tcp (for HTTP), 443/tcp (for HTTPS), 443/udp (for HTTP/3), 2222-2999/tcp (for SSH port forwards), 10001-29999/tcp and 10001-29999/udp (for all other port forwards) to the Load Balancer.
  3. Remove any other relevant/conflicting NAT rules

@runleveldev runleveldev linked an issue Nov 11, 2025 that may be closed by this pull request
Copy link
Collaborator

@cmyers-mieweb cmyers-mieweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@runleveldev runleveldev merged commit 0befaef into main Nov 18, 2025
3 checks passed
@runleveldev runleveldev deleted the 55-nginx-reverse-proxy-add-nginx-layer-4-proxying branch November 18, 2025 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nginx-reverse-proxy: Add NGINX layer-4 proxying

2 participants