[英]Does the nginx “upstream” directive have a port setting?
I use upstream
and proxy
for load balancing. 我使用
upstream
和proxy
进行负载均衡。
The directive proxy_pass http://upstream_name
uses the default port, which is 80. 指令
proxy_pass http://upstream_name
使用默认端口,即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: nginx -t:
[warn]: upstream "myups" may not have port 81 in /opt/nginx/conf/nginx.conf:78.
in your upstream configuration you have ports defined ( 6666 and 9999 ), those are the ports your backend servers need to listen on 在您的上游配置中,您定义了端口(6666和9999),这些是您的后端服务器需要监听的端口
the proxy_pass directive doesn't need an additional port configuration in this case. 在这种情况下,proxy_pass指令不需要额外的端口配置。 Your nginx listens on
port 81
which you've defined in the listen
directive 你的nginx监听你在
listen
指令中定义的port 81
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.