-->

Varnish + nginx + ELB 499 responses

2019-02-16 03:09发布

问题:

I am having varnish 4 server working with nginx as reverse proxy connected to ELB.

Every 2 days or so my server is stop responding and I see 499 responses in nginx access.log

restarting nginx is solving the problem.

Why am I started to get these 499 responses?

Why restarting nginx solving the issue?

回答1:

I solved my issue after understanding two facts:

1) ELB instance has dynamic DNS name

2) nginx resolve DNS names only on reload/restart

The problem was that the ELB changed its IP address and nginx kept the old IP address.

The solution is to use resolver in nginx.conf. Here is my nginx.conf:

http {  

    resolver x.x.x.x valid=30s;

}

server {

    set $elb "example.com";

    location / { 

        proxy_pass http://$elb; 

        }
}  

The resolver IP address should be a DNS server such in /etc/resolv.conf.