Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the nginx "upstream" directive have a port setting?

Tags:

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.

How do I specify an alternate port?

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. 
like image 521
orzzzzz Avatar asked Sep 20 '10 03:09

orzzzzz


People also ask

What is upstream in NGINX configuration?

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.

How does NGINX resolve upstream?

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.

What ports does NGINX use?

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.

What is NGINX upstream module?

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.


1 Answers

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;         }     } } 
like image 147
Michel Feldheim Avatar answered Oct 06 '22 12:10

Michel Feldheim