proxy_pass http://127.0.0.1:8002/1; <-- these should be proxy_pass http://**my_upstream_name**; <--these
然后
upstream my_upstream_name {//Ngixn do a round robin load balance, some users will conect to / and othes to /app2server 127.0.0.1:8001;server 127.0.0.1:8002;}一些 技巧可以 控制代理:
在这里 看看@nginx docs
然后我们开始:
weight = NUMBER- 设置服务器的权重,如果未设置,则权重等于1。不平衡默认循环。
max_fails = NUMBER-
在一定时间内(由参数fail_timeout分配)与服务器通信的失败尝试次数,在此时间内它被认为是无效的。如果未设置,则尝试次数为1。值为0将关闭此检查。可以认为失败的是由proxy_next_upstream或fastcgi_next_upstream定义的(http_404错误不计入max_fails)。
fail_timeout = TIME- 必须发生的时间 max_fails
与服务器通信失败的尝试次数,这将导致服务器被视为无法运行,以及服务器被视为无法运行的时间(在进行另一次尝试之前)
)。如果未设置,则时间为10秒。fail_timeout与上游响应时间无关,请使用proxy_connect_timeout和proxy_read_timeout对此进行控制。
下来 -标记服务器作为永久脱机,与指令ip_hash使用。
备份 -(0.6.7或更高版本)仅在非备份服务器都处于关闭或繁忙状态时才使用此服务器(不能与指令ip_hash一起使用)
EXAMPLE generic upstream my_upstream_name { server backend1.example.com weight=5; server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; server unix:/tmp/backend3; }// proxy_pass http://my_upstream_name;这些是您所需要的:
如果您只是想控制一个应用程序在虚拟主机之间的卸载,请执行以下操作:
upstream my_upstream_name{ server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; server 127.0.0.1:8081 max_fails=3 fail_timeout=30s; server 127.0.0.1:8082 max_fails=3 fail_timeout=30s; server 127.0.0.1:8083 backup;// proxy_pass http://my_upstream_name; // amazingness no.1, the keyword "backup" means that this server should only be used when the rest are non-responsive }如果您有2个或更多应用程序:每个应用程序1个上游,例如:
upstream my_upstream_name{ server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; server 127.0.0.1:8081 max_fails=3 fail_timeout=30s; server 127.0.0.1:8082 max_fails=3 fail_timeout=30s; server 127.0.0.1:8083 backup; } upstream my_upstream_name_app2 { server 127.0.0.1:8084 max_fails=3 fail_timeout=30s; server 127.0.0.1:8085 max_fails=3 fail_timeout=30s; server 127.0.0.1:8086 max_fails=3 fail_timeout=30s; server 127.0.0.1:8087 backup; } upstream my_upstream_name_app3 { server 127.0.0.1:8088 max_fails=3 fail_timeout=30s; server 127.0.0.1:8089 max_fails=3 fail_timeout=30s; server 127.0.0.1:8090 max_fails=3 fail_timeout=30s; server 127.0.0.1:8091 backup; }希望能帮助到你。



