cuber / ngx_http_google_filter_module

Nginx Module for Google Mirror
BSD 2-Clause "Simplified" License
3.35k stars 780 forks source link

nginx 多个upstream 块,能简化配置吗? #117

Closed shmilee closed 8 years ago

shmilee commented 8 years ago

首先,感谢cuber写的这个模块,简化了google镜像的配置。 我通过下面的配置已经可以正常用了(里面的ip并不是现在在用的)。 https://github.com/shmilee/web-in-docker/blob/master/etc/nginx-google.conf#L26

有一点,我要分享一下,国内的网络环境,需要很多域名设置upstream。

    upstream www.google.com
    upstream scholar.google.com
    upstream www.gstatic.com
    upstream encrypted-tbn0.gstatic.com
    upstream encrypted-tbn1.gstatic.com
    upstream encrypted-tbn2.gstatic.com
    upstream encrypted-tbn3.gstatic.com
    upstream ssl.gstatic.com
    upstream apis.google.com

比如,我配置中的 encrypted-tbn0.gstatic.com几个,没有的话,图片就会显示不全,一片一片的灰影。 后面的一些upstream,我也不一定清楚,都是通过日志查看后添加的。

nginx[15592]: 2016/06/22 14:16:23 [error] 15595#15595: *45 no resolver defined to resolve apis.google.com, client: 127.0.0.1, server: localhost, request: "GET ...............

然后,这么多upstream ,它们的内容是一样的,里面的ip十几个,要定期的一起更换。nginx-google.conf#L26 这样写太麻烦。这个问题,可以把那些ip写到一个conf,然后多次include:include google-upstream.conf;

现在我的问题是,那么多个upstream能不能简化一下,我试了一下下面这样的配置,语法通过,

upstream *.gstatic.com {
    include google-upstream.conf;
}

但无法工作(upstream的name,从文档看,应该既不支持这种写法,也不支持多个name1 name2)

[error] 27187#27187: *183 no resolver defined to resolve encrypted-tbn1.gstatic.com, 

PS:其实配置中那些ip能一起更换,已经不错了。后面想合并upstream 做到泛解析,是怕以后又出现什么 xx.google.com no resolver, 一次次加太笨拙。当然,如果没法做到,也没什么的。目前加了那9个upstream,没在日志中发现新的错误。

shmilee commented 8 years ago

upstream apis.google.com