Hi,<br> <br><br>I am implementing varnish cache for multiple seprate domain.i.e <a href="http://sitetwo.com">sitetwo.com</a> and <a href="http://site3.com">site3.com</a><br> <br>I am configured varnish cache on varnish server local ip address (192.168.126.30) <br>
and my one site ip address 192.168.126.20 and two site ip address 192.168.126.60<br> <br>I added multiple backend in VCL file.when I hit site one it calls to backend of site two instead of backend one.<br>for single domain it's working fine but multiple domain not work.<br>
<br>Please help me below some varnish cache configuration files.<br>1)/etc/sysconfig/varnish file<br> <br> <br> VARNISH_VCL_CONF=/etc/varnish/default.vcl<br>#<br># # Default address and port to bind to<br># # Blank address means all IPv4 and IPv6 interfaces, otherwise specify<br>
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.<br> VARNISH_LISTEN_ADDRESS=192.168.126.30<br>#localhost default by hari<br> VARNISH_LISTEN_PORT=80<br>#6081 #by default by hari<br>#<br># # Telnet admin interface listen address and port<br>
VARNISH_ADMIN_LISTEN_ADDRESS=192.168.126.30<br>#127.0.0.1 #by default by hari<br> VARNISH_ADMIN_LISTEN_PORT=6082<br>#<br># # The minimum number of worker threads to start<br> VARNISH_MIN_THREADS=1<br>#<br># # The Maximum number of worker threads to start<br>
VARNISH_MAX_THREADS=1000<br>#<br># # Idle timeout for worker threads<br> VARNISH_THREAD_TIMEOUT=120<br>#<br># # Cache file location<br> VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin<br>#<br># # Cache file size: in bytes, optionally using k / M / G / T suffix,<br>
# # or in percentage of available disk space using the % suffix.<br> VARNISH_STORAGE_SIZE=1G<br>#<br># # Backend storage specification<br> VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"<br>
#<br># # Default TTL used when the backend does not specify one<br> VARNISH_TTL=120<br>#<br># # DAEMON_OPTS is used by the init script. If you add or remove options, make<br># # sure you update this section, too.<br> DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \<br>
-f ${VARNISH_VCL_CONF} \<br> -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \<br> -t ${VARNISH_TTL} \<br> -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \<br>
-u varnish -g varnish \<br> -s ${VARNISH_STORAGE}"<br>#<br>2) /etc/varnish/default.vcl file<br> <br>backend site2 {<br> .host = "<a href="http://sitetwo.com">sitetwo.com</a>";<br>
.port = "8081";<br>}<br>backend site3 {<br> .host = "<a href="http://site3.com">site3.com</a>";<br> .port = "8080";<br>}<br>sub vcl_recv {<br> if (req.request != "GET" &&<br>
req.request != "HEAD" &&<br> req.request != "PUT" &&<br> req.request != "POST" &&<br> req.request != "TRACE" &&<br> req.request != "OPTIONS" &&<br>
req.request != "DELETE") {<br># /* Non-RFC2616 or CONNECT which is weird. */<br> return (pipe);<br> }<br> if (req.request != "GET" && req.request != "HEAD") {<br>
# /* We only deal with GET and HEAD by default */<br> return (pass);<br> }<br> if (req.http.Authorization || req.http.Cookie) {<br># /* Not cacheable by default */<br> return (pass);<br> }<br>
if (req.http.host == "<a href="http://site3.com">site3.com</a>") {<br> #You will need the following line only if your backend has multiple virtual host names<br> set req.http.host = "<a href="http://site3.com">site3.com</a>";<br>
set req.http.X-Orig-Host = req.http.host;<br> set req.backend = site3;<br> return (lookup);<br>}<br>if (req.http.host == "<a href="http://sitetwo.com">sitetwo.com</a>") {<br> #You will need the following line only if your backend has multiple virtual host names<br>
set req.http.host = "<a href="http://sitetwo.com">sitetwo.com</a>";<br> set req.http.X-Orig-Host = req.http.host;<br> set req.backend = site2;<br> return (lookup);<br>}<br> return (lookup);<br>
}<br>#<br>sub vcl_pipe {<br># # Note that only the first request to the backend will have<br># # X-Forwarded-For set. If you use X-Forwarded-For and want to<br># # have it set for all requests, make sure to have:<br>
# # set req.http.connection = "close";<br># # here. It is not set by default as it might break some broken web<br># # applications, like IIS with NTLM authentication.<br> return (pipe);<br>}<br>#<br>
sub vcl_pass {<br> return (pass);<br>}<br>#<br>sub vcl_hash {<br> set req.hash += req.url;<br> if (req.http.host) {<br> set req.hash += req.http.host;<br> } else {<br> set req.hash += server.ip;<br>
}<br> return (hash);<br>}<br>#<br>sub vcl_hit {<br> if (!obj.cacheable) {<br> return (pass);<br> }<br> return (deliver);<br>}<br>#<br>sub vcl_miss {<br> return (fetch);<br>}<br>sub vcl_fetch {<br>
if (!obj.cacheable) {<br> return (pass);<br> }<br> if (obj.http.Set-Cookie) {<br> return (pass);<br> }<br> ##set obj.prefetch = 30s;<br>#The following vcl code will make Varnish serve expired objects. All object will be kept up to two minutes past their expiration time or a fresh object is generated<br>
set obj.grace = 2m;<br> return (deliver);<br>}<br>#<br>sub vcl_deliver {<br> return (deliver);<br>}<br> <br>Thanks in Advanced <br> <br> <br>Thanks,<br>Hari Metkari<br>+91-9881462183