Welcome! Log In Create A New Profile

Advanced

RE: Using NGINX to reverse proxy hundreds of ports

Reinis Rozitis
March 02, 2020 02:04PM
> I get that the NGINX listen statement works on an individual port basis, so the equivalent of what's below in NGINX would at the very least require 300 listen statements.

You can listen on a port range (see below).



> FYI I've tried referencing my own declared variables from within the upstream as well as referencing $server_port but of course these don't appear to be in scope.

Depends if you want nginx to perform any active healthchecks and what kind of backends those are.

If it is http and you just need to redirect traffic instead of defining upstreams a configuration with (way) less lines could be:

server {
listen 10.1.0.1:2000-2299;
location / { proxy_pass http://127.0.0.1:$server_port; }
}


A fallback to another proxy could be configured via error_page (502).
Something like:

error_page 502 @fallback;
location @fallback { proxy_pass http://10.1.0.2:$server_port; }

But I don't think there is a way (at least in the base vanilla) nginx to configure upstreams in a dynamic way with port ranges as in upstream {} doesn't support variables for the server definitions.

rr



_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Using NGINX to reverse proxy hundreds of ports

Phillip Odam March 02, 2020 10:34AM

RE: Using NGINX to reverse proxy hundreds of ports

Reinis Rozitis March 02, 2020 02:04PM

Re: Using NGINX to reverse proxy hundreds of ports

Phillip Odam March 02, 2020 04:22PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 253
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready