0

i have one web server which is IIS that is back on varnish. there are more web sites on ISS. there are all web sites header's on IIS and all web sites publish from port 80. can i cache all web site by varnish like below code;

backend cacheWebSite{.host = "192.168.0.1"; .port = "80";} sub vcl_recv {if (req.http.host == "www.example1.com") {set req.backend = CacheWebSites;} if (req.http.host == "www.example2.com") {set req.backend = CacheWebSites; } if (req.http.host == "www.example3.com") {set req.backend = CacheWebSites; }}

i can't test this code. that is just senario. thank you for your help already now.

Kerberos
  • 123
  • 4

1 Answers1

1

If you are caching many sites behind one varnish instance, and those sites exist on the same machine, you really don't need to do anything more than set:

backend default {
  .host = "192.168.0.1"; 
  .port = "80";
}

As long as the backend answers properly, Varnish will handle this fine. You would use if blocks to alter the hostname being passed to the backend, or, if you needed to do load balancing, etc. In your case, specifying the default backend without any other VCL will do what you need.

  • okay thank you for yor help. so did i write if block right? – Kerberos Apr 02 '10 at 20:19
  • If you have 1 varnish server in front of your origin server, you don't need the if block. –  Apr 02 '10 at 21:05
  • acctually, we have 2 varnish servers (they are have internal ip) and we are making load balance with a public (real) ip by hardware. varnish servers make load balance two iis servers (they are have internal ip) too. iis servers are back side of varnish servers and we want to cache 5 web sites which are on iis with 2 varnish servers. domains are on iis like that; www.domain1.com, www1.domain2.com, www2.domain2.com, www.domain3.com, www.domain4.com – Kerberos Apr 02 '10 at 21:32
  • If both varnish machines are pointing to one origin server, you don't need the if block. You only need the if blocks when you need to force a domain to use a different backend. Even with load balancing, as long as each origin server can serve all domains, you won't need any extra VCL. –  Apr 02 '10 at 21:42
  • okay, what does "backend" mean about mine structure? it is IIS server, is it? – Kerberos Apr 02 '10 at 22:11
  • backend is the configuration entry in varnish which corresponds to your origin server -- IIS in this case. Since both varnish servers are pointing to IIS machines that are serving identical content, you won't need to do any VCL in vcl_recv. The only time you need to do special backend processing is when you have a varnish server that needs to send some requests to one origin server, and some requests to a separate origin server. I.e. static content versus application server. –  Apr 02 '10 at 23:53
  • ok, thank you very much. i am sorry, i am new on varnish and i don't have test platform to apply codes. i just read varnish documention. there are many things still which are i did'nt understand but i understood as per you wrote if IIS publishs same web sites everthing will work fine with "backend default{...}" code, won't it? – Kerberos Apr 03 '10 at 12:54
  • If IIS publishes everything, all you really need is the backend default {...} code. The only time you need additional VCL is when you are manipulating which backend you are sending requests to or modifying the request object in some manner. –  Apr 03 '10 at 18:49
  • thank you very much for your valent information. best regards. – Kerberos Apr 03 '10 at 22:01