Results 1 to 5 of 5
-
5th Dec 2011, 02:36 PM #1OPMemberWebsite's:
host4offshore.comVarnish Cache for WordPress on cPanel
Varnish is an extremely easy to configure server cache software that can help you counter the ?slashdot effect? ? high traffic over a small period of time. The way Varnish does this is by sitting between the client and the webserver and providing cached results to the client so that the server doesn?t have to process every page. It?s better than memcache etc because the request never gets to the webserver. You can avoid one of the bottlenecks this way. In this tutorial, we?ll cover how to setup Varnish on a VPS (or dedicated server) where you have root access and are running your site using cPanel/WHM. It also applies to situations where you don?t have cPanel/WHM. You can just skip the cPanel portion if that?s the case. So, let?s get started.
First, you need to get Varnish. It?s very easy to setup since it comes with its own repository for CentOS. It does have on dependency that?s normally missing. That dependency is jemalloc.so. When you try to install varnish, it gives the error:
Missing Dependency: libjemalloc.so.1()(64bit) is needed by package varnish-3.0.0-1.el5.x86_64 (varnish-3.0)
Get this file and install it using the following commands:
wget http://download.fedora.redhat.com/pu...el5.x86_64.rpm
rpm -ivh jemalloc-2.1.3-2.el5.x86_64.rpm
Now we have the dependency. Head over to Varnish Docs page and read the instructions for your operating system. Since I?m describing CentOS, here are the instructions for that:
rpm --nosignature -i http://repo.varnish-cache.org/redhat...0-1.noarch.rpm
yum install varnish
Now to edit the varnish configuration file. It?s located at: etc/varnish/default.vcl. Insert the following code in the file. Explanation of the different constructs follows:
Code:backend default { .host = "your.primary.domainname.com"; .port = "80"; } sub vcl_recv { if (req.http.Accept-Encoding) { if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|lzma|tbz)(\?.*|)$") { remove req.http.Accept-Encoding; } elsif (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } elsif (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { remove req.http.Accept-Encoding; } } if (req.url ~ "^/[^?]+\.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.*|)$") { unset req.http.cookie; } if (req.request == "GET" && req.url ~ "cron_job" || req.url ~ "something_else" ) { return ( pass ); } }
The sub vcl_recv portion gets called before a request gets passed to the backend or gets checked in the cache. You can define different rules here. For example, the rule if (req.url ~ "^/[^?]+\.(jpeg| ... says that if the requested URL matches one of those extensions, the http cookie should be unset. This is important because if a cookie is present in any request, varnish will always bypass the cache and send the request to the webserver. By unsetting the cookie, you?re giving varnish a chance to check if a cache hit will occur.
The second important line here is the return(pass); directive. Whenever this gets called, the cache is ignored again and the request is passed through to the webserver. In our case, if the request URL contains either the word ?cron_job? or ?something_else?, it gets ignored by varnish. You might want to do this if (as in this case), there?s a cron job that does not have a cookie but still needs to be called on the webserver each time.
Ok, enough talk. Let?s start varnish. Here?s the command:
varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:8080
It reads the configuration file given by the -f directive, allocates 1GB memory to varnish, sets up an admin interface on port 2000 and sets up the varnish listening port on 8080. Notice that we currently have varnish set on 8080 and the webserver on 80. This is so that we can test varnish without disrupting the normal processing of the server. After we?re done testing, we?ll change the webserver to 8080 and varnish to 80.
To see the status of varnish request processing, run varnishtop on the shell and send a request to your server on port 8080.
To configure a running instance of varnish, you can use the varnishadm command. For example, run varnishadm and issue the following commands to reload the configuration file (after you?ve made some changes to it).
help
vcl.load reload01 /etc/varnish/default.vcl
vcl.use reload01
Finally, when you have everything ready, it?s time to kill varnish, change the server port to 8080 and re-run varnish on port 80. First,
killall varnishd
Edit the configuration file and change backend port to 8080 instead of 80.
cPanel/WHM configuration
This one?s easy. If you?re just using apache, change all listening ports to 8080 and change your vhost directives. If you?re using cPanel/WHM, go to WHM -> Tweak Settings and change ?Apache non-SSL IP/port? to ?0.0.0.0:8080″. (If you have apache listening on a specific IP, you can change the 0s accordingly).
Now, save, restart apache and issue the following command to start varnish:
varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:80
You should now be able to browse the site and check varnishtop to see that varnish is processing the requests. You might also want to put the command (prefixing it with /usr/bin/varnishd instead of varnishd) in /etc/rc.local so that varnish starts on reboot.onel0ve Reviewed by onel0ve on . Varnish Cache for WordPress on cPanel Varnish is an extremely easy to configure server cache software that can help you counter the ?slashdot effect? ? high traffic over a small period of time. The way Varnish does this is by sitting between the client and the webserver and providing cached results to the client so that the server doesn?t have to process every page. It?s better than memcache etc because the request never gets to the webserver. You can avoid one of the bottlenecks this way. In this tutorial, we?ll cover how Rating: 5|| Host4Offshore :: Reliable, Quality, Fast Offshore Hosting Solution (USA/Netherlands/Sweden/Russia/Romania)
|| Shared , Reseller Hosting Sales Thread
|| Rapidleech Hosting Sales Thread
|| Current Promotion
-
12th Jan 2012, 03:24 AM #2Member
I'm trying to get Nginx working with Varnish. I have Varnish set on Port 80, and in Nginx.conf to port 8080. Saved and rebooted all services.
So my question is:
How do I know Varnish is Working? VS my website being just served up by Nginx. If I visit mydomain.com:80 the site loads, if I go to mydomain.com:8080 I got 403 Forbidden.
I also ran Varnishtop command and this is what I get:
PHP Code:list length 35
15.23 CLI Rd ping
0.98 CLI Wr 200 19 PONG 1326338445 1.0
0.95 CLI Wr 200 19 PONG 1326338442 1.0
0.92 CLI Wr 200 19 PONG 1326338439 1.0
0.89 CLI Wr 200 19 PONG 1326338436 1.0
0.87 CLI Wr 200 19 PONG 1326338433 1.0
0.83 CLI Wr 200 19 PONG 1326338430 1.0
0.81 CLI Wr 200 19 PONG 1326338427 1.0
0.79 CLI Wr 200 19 PONG 1326338424 1.0
0.76 CLI Wr 200 19 PONG 1326338421 1.0
0.74 CLI Wr 200 19 PONG 1326338418 1.0
0.72 CLI Wr 200 19 PONG 1326338415 1.0
0.70 CLI Wr 200 19 PONG 1326338412 1.0
0.69 CLI Wr 200 19 PONG 1326338409 1.0
0.67 CLI Wr 200 19 PONG 1326338406 1.0
0.65 CLI Wr 200 19 PONG 1326338403 1.0
0.64 CLI Wr 200 19 PONG 1326338400 1.0
0.62 CLI Wr 200 19 PONG 1326338397 1.0
0.60 CLI Wr 200 19 PONG 1326338394 1.0
0.59 CLI Wr 200 19 PONG 1326338391 1.0
0.57 CLI Wr 200 19 PONG 1326338388 1.0
0.55 CLI Wr 200 19 PONG 1326338385 1.0
-
12th Jan 2012, 05:18 AM #3Member
Why are you running Varnish on port 80 though.
The better setup I've seen and used is Nginx + Apache + Varnish.
Nginx handles static content, any dynamic content is passed through to Apache and if Apache is under load, Varnish displays the cache instead.
Nginx:80
Varnish:6081
Apache:8080This is the staff, you have been banned
-
12th Jan 2012, 11:33 AM #4Member
onel0ve's tutorial says..
Notice that we currently have varnish set on 8080 and the webserver on 80. This is so that we can test varnish without disrupting the normal processing of the server. After we?re done testing, we?ll change the webserver to 8080 and varnish to 80.
I'll just be running Wordpress sites with W3 Total Cache to generate static files for Nginx and the caching for Varnish. Trying not to use Apache to minimize footprint and conserve as much resources as possible for the sites, and future growth.
I've Googled and followed tutorials on getting Nginx, Wordpress and W3 Total Cache working, but I can't seem to find anything easily understandable on how to add Varnish into the mix.
Some guidance would be very much appreciated, thanks in advance =]
-
13th Jan 2012, 01:20 PM #5Member
Nada? Nothing? Where's all the server guru's at!
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Which cache plugin do you use for wordpress?
By Mr.Mirchi in forum Polling PlazaReplies: 29Last Post: 4th Sep 2012, 08:31 PM -
how to install varnish in cpanel ?
By onel0ve in forum Server ManagementReplies: 10Last Post: 6th Jul 2011, 10:13 PM -
[Wordpress] WP Super Cache or W3 Total Cache ?
By Rocke in forum Polling PlazaReplies: 13Last Post: 13th Dec 2010, 06:00 PM
themaRegister - register to forums...
Version 3.45 released. Open older version (or...