CyberKeeda In Social Media

Varnish Cache Server Configuration





Varnish is now installed under the /usr/local directory.
The full path to the main binary is /usr/local/sbin/varnishd.
The default configuration file is /usr/local/etc/varnish/default.vcl.



You can start Varnish by running the varnishd binary. Before you can do that though, you have to tell Varnish which back-end server it's caching for. Let's specify the back end in the default.vcl file. Edit the default.vcl file as shown below, substituting the values for those of your Web server:

Note -:  Important is 1st to Change your Apache's http.conf  Listen port to 8080 

I assume varnishd is in your path. You might want to run pkill varnishd to make sure varnishd isn't running. Become root and type:


[root@cyberkeeda etc]# vim /usr/local/etc/varnish/default.vcl

 backend default {
     .host = "127.0.0.1";
     .port = "8080";
 }

# pkill varnishd

Now you can start Varnish with this command:

[root@cyberkeeda etc]# /usr/local/sbin/varnishd -f /usr/local/etc/varnish/default.vcl -a :6081 -P /var/run/varnish.pid -s malloc,256m

Here Apache is using Varnish Cache using port 6081 -- http:/localhost:6081

The moment you want to move it under production replace it by port 80

# pkill varnishd

[root@cyberkeeda etc]# /usr/local/sbin/varnishd -f /usr/local/etc/varnish/default.vcl -a :80 -P /var/run/varnish.pid -s malloc,256m

Now you can directly open --: http://localhost


If you installed Varnish from your package manager, it may be running already. In that case, you can stop it first, then use the command above to start it manually. Otherwise, the options it was started with may differ from those in this example. A quick way to see if Varnish is running and what options it was given is with the pgrep command:

/usr/bin/pgrep -lf varnish
Varnish now will relay any requests it receives to the back end you specified, possibly cache the response, and deliver the response back to the client. Let's submit some simple GET requests and see what Varnish does. First, run these two commands on separate terminals:

/usr/local/bin/varnishlog
/usr/local/bin/varnishstat

To view communication between Varnish and the client (omitting the back end):

/usr/local/bin/varnishlog -c
To view communication between Varnish and the back end (omitting the client):

/usr/local/bin/varnishlog -b
To view the headers received by Varnish (both the client's request headers and the back end's response headers):

/usr/local/bin/varnishlog -i RxHeader
Same thing, but limited to just the client's request headers:

/usr/local/bin/varnishlog -c -i RxHeader
Same thing, but limited to just the back end's response headers:

/usr/local/bin/varnishlog -b -i RxHeader
To write all log messages to the /var/log/varnish.log file and dæmonize:

/usr/local/bin/varnishlog -Dw /var/log/varnish.log
To read and display all log messages from the /var/log/varnish.log file:

/usr/local/bin/varnishlog -r /var/log/varnish.log

No comments:

Post a Comment

Designed By Jackuna