I have an Apache 2 on Centos + bind with a wordpress website on it (e.g example.com). I have also set up, on another server in a different country a load balancer (varnish:80 + nginx 127.0.0.1:8080) for it - which task is to server all static content under /wp-content/.
Using Simple DNS editor I added an A entry to cdn.example.com pointing to the server's IP. So no extra work from a 2nd dns server.
Then using htaccess I redirect all requests to jpg|gif|css|js files to cdn.example.com. That works and all files are saved on the "cdn" server and served right away.
My problem is that for the first time I enter on example.com (e.g after restarting the computer or closing the browser) the load time is 1 up to 3 seconds, while any subsequent page loads take only 300 to 600 miliseconds.
I know it might be a DNS issue, but I have done a cache check on several websites and cdn.example.com indicates the right IP.
Do you have any ideas where I should dig to solve this first-time slowness?
I made a static version (.htm) of my index.php and tried some tests on it. And I noticed something interesting: some images load very slow.
As I've seen in Google Developer tools:
Waiting _ _ _ _ _ _ 3.04s. That's not good, maybe varnish is experiencing some issues...