I have istalled Varnish on Debian.
I have a website running on Apache on http://example.com
Here's my /etc/varnish/default
vcl 4.0;
backend default {
.host = "example.com";
.port = "8080";
}
Varnish starts, I can see the content of the website at http://127.0.0.1:6081/
Response headers:
Pragma: no-cache
Date: Tue, 25 Aug 2015 12:29:38 GMT
Content-Encoding: gzip
Server: Apache/2.4.10 (Ubuntu)
Age: 0
X-Powered-By: PHP/5.6.4-4ubuntu6.2
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Via: 1.1 varnish-v4
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
X-Varnish: 229436
Connection: keep-alive
Accept-Ranges: bytes
Content-Length: 23044
Expires: Thu, 19 Nov 1981 08:52:00 GMT
200 OK
How can I make this visible under http://example.com ? How to configure Varnish and Apache vhost?
In your /etc/hosts file, add example.com and any other vhost name on the 127.0.0.1 IP. When varnish accesses "example.com" it will be resolved to 127.0.0.1, but the correct hostname header will follow with the request to apache, which in its turn will be able to map it to the correct vhost. No special configuration should be needed in apache nor varnish, just configure vhosts as normal in apache.