How to specify search domain name of nginx resolver for proxy_pass
Posted
by
myjpa
on Server Fault
See other posts from Server Fault
or by myjpa
Published on 2012-01-18T10:38:29Z
Indexed on
2012/03/26
5:31 UTC
Read the original article
Hit count: 561
Assuming my server is www.mydomain.com, on Nginx 1.0.6
I'm trying to proxy all request to http://www.mydomain.com/fetch to other hosts, the destination URL is specified as a GET parameter named "url".
For instance, when user requests either one:
http://www.mydomain.com/fetch?url=http://another-server.mydomain.com/foo/bar
http://www.mydomain.com/fetch?url=http://another-server/foo/bar
it should be proxyed to
http://another-server.mydomain.com/foo/bar
I'm using the following nginx config and it works fine only if the url paramter contains domain name, like http://another-server.mydomain.com/...; but fails on http://another-server/... on error:
another-server could not be resolved (3: Host not found)
nginx.conf is:
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;
}
}
Here, I'd like to resolve all URL without domain name as host name in mydomain.com, in /etc/resolv.conf, it's possible to specify default search domain name for the whole Linux system, but it doesn't affect nginx resolver:
search mydomain.com
Is it possible in Nginx? Or alternatively, how to "rewrite" the url parameter so that I can add the domain name?
© Server Fault or respective owner