I'd like to see how to configure Nginx and Varnish.
I'm running several PHP sites and Rack-Sinatra sites as virtual hosts across two IP's. I'd like to prevent Nginx from having to serve static files, since I'm noticing some delays.
Edit: I've changed to Nginx, but the answer provided is pretty easy to port over to nginx.
Apache will still serve static files, but it will only serve them once. Perhaps the easiest way is to configure varnish to listen on all IP addresses for port 80, and configure Apache to listen to on
localhost:8000
for example. Then you configure varnish to forward all requests it receives tolocalhost:8000
for Apache to handle.I would go with a varnish configuration of:
Now within your
vcl
file:Now within your Apache
httpd.conf
configuration, you want Apache to listen onlocalhost:8000
and define your virtual hosts on the same address:portFor each website, create a
<VirtualHost>
stanza. Within that stanza you need to tell Apache to set theExpires
and cache-control headers on all static content so varnish knows to cache it.I hope this helps.
For the benefit of future readers, for the VCL example provides by rjk:
Otherwise, spot on. :)