Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.
share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

You should set the port only in "server" statements inside "upstream" definition.

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.