Julian H. Lam
Julian H. Lam

Reputation: 26124

Proxy cache timeout/delay with nginx?

To give you a bit of background on my problem:

I have an app that installs software and serves it publically. When it installs:

  1. Installs base files to root path (i.e. /var/www/{site})
  2. Creates a new nginx configuration file and places it in /etc/nginx/sites-available/{site}
  3. Creates a symlink to that file from /etc/nginx/sites-enabled/{site}
  4. Reloads the nginx configuration: service nginx reload
  5. Sends an API call to CloudFlare to direct all requests from {site}.mydomain.com to the server's IP address

After that, {site}.mydomain.com should work, except... it doesn't!

... Until you wait ~5 minutes, and then it magically starts working. Is there a delay before proxying comes into effect with nginx?

If I delete {site} and readd it (same process as above), even if it was working before, it stops working for awhile before starting to work again.

I'm at a loss to explain what's happening!

nginx config (where {site} is foobar)

upstream mydomain_foobar {
    server 127.0.0.1:4567;
}

server {
    listen 80;

    server_name foobar.mydomain.com;
    root /var/www/mydomain/foobar/;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://mydomain-foobar/;
        proxy_redirect off;

        # Socket.io Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Upvotes: 2

Views: 1913

Answers (1)

Julian H. Lam
Julian H. Lam

Reputation: 26124

After looking at this issue on and off over the past month, it turns out the issue was not related to nginx at all.

When a rec_new API call is sent to CloudFlare, it takes roughly five minutes (300s TTL) for their records to update. The same can be said for any other DNS related API call to CloudFlare.

This explains the five minute gap.

From Cloudflare:

Hi,

DNS updates should take place after about five minutes (the ttl is 300 seconds). It may take a little longer to propagate out everywhere on the web (recursive DNS caching by your ISP, for example).

Upvotes: 2

Related Questions