I use upstream
and proxy
for load balancing.
The directive proxy_pass http://upstream_name
uses the default port, which is 80.
However, if the upstream server does not listen on this port, then the request fails.
my configuration:
http{ #... upstream myups{ server 192.168.1.100:6666; server 192.168.1.101:9999; } #.... server{ listen 81; #..... location ~ /myapp { proxy_pass http://myups:81/; } }
nginx -t:
[warn]: upstream "myups" may not have port 81 in /opt/nginx/conf/nginx.conf:78.
upstream defines a cluster that you can proxy requests to. It's commonly used for defining either a web server cluster for load balancing, or an app server cluster for routing / load balancing.
Upstream Domain Resolve¶ Its buffer has the latest IPs of the backend domain name and it integrates with the configured load balancing algorithm (least_conn, hash, etc) or the built in round robin if none is explicitly defined. At every interval (one second by default), it resolves the domain name.
By default, the Nginx HTTP server listens for inbound connections and connects to port 80, which is the default web port. However, the TLS configuration, which is not supported in Nginx by default, listens to port 443 for secure connections.
NGINX is a load-balancing tool widely used in the IT industry. It is a web server that can be used as a reverse proxy, mail proxy, or an HTTP cache. Upstream is a module used in NGINX to define the servers to be load balanced.
in your upstream configuration you have ports defined ( 6666 and 9999 ), those are the ports your backend servers need to listen on
the proxy_pass directive doesn't need an additional port configuration in this case. Your nginx listens on port 81
which you've defined in the listen
directive
Is this what you tried to do?
http { #... upstream upstream_1{ server 192.168.1.100:6666; server 192.168.1.101:9999; } upstream upstream_2{ server 192.168.1.100:6661; // other backstream port if you use port 81 server 192.168.1.101:9991; } server { listen 80; #..... location ~ /myapp { proxy_pass http://upstream_1; } } server { listen 81; #..... location ~ /myapp { proxy_pass http://upstream_2; } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With