nginx上游复制上游

nginx上游复制上游,nginx,Nginx,我使用的场景是这样的: www.a.com.conf …… upstream a_cluster_backend { server 1.1.1.1:80 weight=1 max_fails=2 fail_timeout=10s; server 1.1.1.2:80 weight=1 max_fails=2 fail_timeout=10s; } …… location / { proxy_pass http://a_cluster_backend; } ……

我使用的场景是这样的:

www.a.com.conf

……
upstream a_cluster_backend {
    server   1.1.1.1:80 weight=1 max_fails=2 fail_timeout=10s;
    server   1.1.1.2:80 weight=1 max_fails=2 fail_timeout=10s;
}
……
location / {
    proxy_pass http://a_cluster_backend;
}
……
include vhosts/cluster.ini;
……
location / {
    proxy_pass http://cluster_backend;
}
www.b.mi.com.conf

……
upstream b_cluster_backend {
    server   1.1.1.1:80 weight=1 max_fails=2 fail_timeout=10s;
    server   1.1.1.2:80 weight=1 max_fails=2 fail_timeout=10s;
}
……
location / {
    proxy_pass http://b_cluster_backend;
}
……
include vhosts/cluster.ini;
……
location / {
    proxy_pass http://cluster_backend;
}
每次我关闭一台服务器的同时,要更改上面的两个配置文件,我想让主机独立,然后将两个配置文件包括在内,这样每行文件都只能修改。 像这样:

www.a.com.conf

……
upstream a_cluster_backend {
    server   1.1.1.1:80 weight=1 max_fails=2 fail_timeout=10s;
    server   1.1.1.2:80 weight=1 max_fails=2 fail_timeout=10s;
}
……
location / {
    proxy_pass http://a_cluster_backend;
}
……
include vhosts/cluster.ini;
……
location / {
    proxy_pass http://cluster_backend;
}
www.b.mi.com.conf

……
upstream b_cluster_backend {
    server   1.1.1.1:80 weight=1 max_fails=2 fail_timeout=10s;
    server   1.1.1.2:80 weight=1 max_fails=2 fail_timeout=10s;
}
……
location / {
    proxy_pass http://b_cluster_backend;
}
……
include vhosts/cluster.ini;
……
location / {
    proxy_pass http://cluster_backend;
}
cluster.ini

upstream cluster_backend {
    server   1.1.1.1:80 weight=1 max_fails=2 fail_timeout=10s;
    server   1.1.1.2:80 weight=1 max_fails=2 fail_timeout=10s;  
    }
其实这还不够,它会提示不支持,如下所示:

nginx: [emerg] duplicate upstream "cluster_backend" in /usr/local/nginx/conf/vhosts/cluster.ini:1
configuration file /usr/local/nginx/conf/nginx.conf test failed
问一下,在这个场景中我做的更方便,只是想把主机独立起来,让更多的vhost包含进来。所以我vhosts同时使用多台机器,一台停机的服务器,只需要修改一个vhosts文件就可以了 增加了对上游、编译中包含代码的支持

 306 static ngx_command_t  ngx_http_upstream_commands[] = {
 307
 308     { ngx_string("upstream"),
 309                  NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
 310       ngx_http_upstream,
 311       0,
 312       0,
 313       NULL },
 + 314     { ngx_string("include"),
 + 315       NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
 + 316       ngx_conf_include,
 + 317       0,
 + 318       0,
 + 319       NULL },
 320
 321     { ngx_string("server"),
 322       NGX_HTTP_UPS_CONF|NGX_CONF_1MORE,
 323       ngx_http_upstream_server,
 324       NGX_HTTP_SRV_CONF_OFFSET,
 325       0,
 326       NULL },
 327
 328       ngx_null_command
 329 };
见: