Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have nginx/0.7.68 running on my CentOS box with the following configuration

server {
    listen       80;
    server_name ***;
    index index.html index.htm index.php default.html default.htm default.php;

    location / {
            root   /***;
            proxy_pass   http://***:8888;
            index  index.html index.htm;
    }
[...]

The server that my nginx proxy_pass to is a server with dynamic DNS, whose IP change frequently. The problem is that nginx seems to cache the IP address of the destination of proxy_pass, resulting request to the wrong IP address.

How can I solve this problem?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

It's an intriguing question and AFAIK that's not going to work well. You can try to use the upstream module and use the directives for failover to see if it works as a hack.

share|improve this answer
1  
surprisingly when i changed to upstream, everything worked as expected. I'll then mark this as correct answer –  xiamx Feb 27 '11 at 22:20

Accepted answer didn't work for me on nginx/1.4.2.

Setting proxy_pass to a variable forces re-resolution of the DNS names, because Nginx treats variables differently to static configuration.

Example:

server {
    ...
    resolver 127.0.0.1;
    set $backend "http://dynamic.example.com:80";
    proxy_pass $backend;
    ...
}

Note: A resolver (e.g. the name server you use) MUST be configured for this to work.

Source: http://forum.nginx.org/read.php?2,215830,215832#msg-215832

share|improve this answer

looking through the nginx source, it does appear nginx is hardcoded to cache resolves for their TTL - what's the TTL on your dynamic dns?

share|improve this answer
    
TTL on my ddns is 60s, the default value of dyndns.com –  xiamx Feb 26 '11 at 3:19

Your Answer

 
discard

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.