Friday, January 28, 2011

Does the nginx “upstream” directive have a port setting?

moved from:http://stackoverflow.com/questions/3748517/does-nginx-upstream-has-a-port-setting

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.
  • You should set the port only in "server" statements inside "upstream" definition.

    (Which port does it listen on? 6666, 9999 or 81?)

  • I think you are misinterpreting the meaning of the line:

    proxy_pass http://myups;

    This line is telling nginx to pass the request to one of the servers listed in the 'upstream myups' block. It is not going back out on to the internet to send a request to URL for the proxy_pass.

    In other words, when a request come in to the nginx server on port 81 for the hostname you specified, it will pass the request on to either 192.168.1.100:6666, or 192.168.1.101:9999.

    Hope this clears it up a bit.

    From jammur

0 comments:

Post a Comment