如何为proxy_pass指定nginxparsing器的search域名

假设我的服务器是www.mydomain.com ,在Nginx 1.0.6上

我试图代理所有的请求到http://www.mydomain.com/fetch到其他主机,目标URL被指定为一个名为“url”的GET参数。

例如,当用户请求任一个时:

http://www.mydomain.com/fetch?url=http://another-server.mydomain.com/foo/bar http://www.mydomain.com/fetch?url=http://another-server/foo/bar 

它应该被委托给

 http://another-server.mydomain.com/foo/bar 

我使用下面的nginxconfiguration,只有当url参数包含域名才能正常工作,比如http://another-server.mydomain.com/ … ; 但在http:// another-server / …上出现错误:

 another-server could not be resolved (3: Host not found) 

nginx.conf是:

 http { ... # the DNS server resolver 171.10.129.16; server { listen 80; server_name localhost; root /path/to/site/root; location = /fetch { proxy_pass $arg_url; } } 

在这里,我想parsing所有在mydomain.com中没有域名的URL作为主机名,在/etc/resolv.conf中,可以指定整个Linux系统的默认search域名,但是不影响nginxparsing:

 search mydomain.com 

Nginx可能吗? 或者,如何“重写”url参数,以便我可以添加域名?

nginx执行自己的DNSparsing,不使用libc库,这就是为什么/etc/resolv.conf没有效果。 我找不到指定search域的任何选项,所以重写URL是唯一的select。 像这样的事情应该做的伎俩:

 location /fetch { # Don't rewrite if we've already rewritten or the request already contains the full domain if ($arg_url !~ mydomain.com) { rewrite ^/fetch?url=http://([^/]+)(/?.*)$ /fetch?url=http://$1.mydomain.com$2; } proxy_pass $arg_url; }