Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Assuming my server is, on Nginx 1.0.6

I'm trying to proxy all request to to other hosts, the destination URL is specified as a GET parameter named "url".

For instance, when user requests either one:

it should be proxyed to

I'm using the following nginx config and it works fine only if the url paramter contains domain name, like; 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
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, 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:


Is it possible in Nginx? Or alternatively, how to "rewrite" the url parameter so that I can add the domain name?

share|improve this question
up vote 0 down vote accepted

nginx performs its own DNS resolution and doesn't use the libc library, which is why /etc/resolv.conf doesn't have an effect. I can't find any option to specify a search domain, so rewriting the URL is your only option. Something like this should do the trick:

location /fetch {
    # Don't rewrite if we've already rewritten or the request already contains the full domain
    if ($arg_url !~ {
        rewrite ^/fetch?url=http://([^/]+)(/?.*)$ /fetch?url=http://$$2;
    proxy_pass $arg_url;
share|improve this answer
It looks the only working solution – myjpa Apr 16 '12 at 2:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.