• Home
  • Cloud
    • General
    • SaaS
    • BPaaS
    • PaaS
    • IaaS
    • Other Internet Hosted Applications
      • WordPress
        • WooThemes Canvas
          • WooThemes Canvas CSS
  • About me
  • Why Badly Wired?
  • Contact

Badly Wired

Connecting WordPress via APIs, Plugins and other stuff - a technical notebook

You are here: Home / Linux / Setting up Varnish with Virtualmin – Centos in 5 steps

Setting up Varnish with Virtualmin – Centos in 5 steps

27th September 2013 by Alan 13 Comments

Fully Managed UK Hosting - Only £1+VAT till 1st Jan 2021 on Shared, Reseller and Dedicated Hosting! .... read more ....

I have just finished setting up Varnish on my test server that uses Webmin/Virtualmin, with Apache on Centos.

It has been a little bit of a voyage of discovery but I think I have cracked it. Much of what I have here is based on many other blogs and forums. In essence once you know how its easy, but there are a few pit holes to watch for in Virtualmin/Webmin, as editing the underlying httpd.conf file isn’t the way to go.

Fully Managed UK Hosting - Only £1+VAT till 1st Jan 2021 on Shared, Reseller and Dedicated Hosting! .... read more ....

The main steps are

  1. Get Varnish
  2. Set up the Varnish control file
  3. Modify the Apache virtual hosts port number
  4. Restart the servers
  5. Tidy up Virtualmin server templates and make sure that Varnish runs on boot / restarted with Apache

and you are done.  My experience is on a Centos server, I’m sure that the process is the same on Ubuntu except the details of some of the linux level commands and file locations

1. Get Varnish

The easy way – from a repository

yum install varnish

2. Set up the Varnish control file & process defaults

In essence to get up and running this is simply putting the port and IP address that Apache will be listening on.     Normally Apache listens on the http port 80, but as Varnish sits in front of Apache, Apache and Varnish will listen on 80 apache has to move – the ‘default’ documentation moves Apache to 8080.

Some people write that they can set it up with Apache listening on 127.0.0.1:80 and Varnish on myexternalIP:80  but I couldn’t get this to work and wasted much time trying to work out where the conflict comes from. If you don’t want to waste time stick to 80 and 8080.

The default.vcl is in etc/varnish

There are a lot more advanced VCL things that you might have to do, like excluding some virtual hosts, and passing through the originators IP address (that Varnish looses as it is a proxy) I’ll cover them in my ‘advanced’ VCL musing in a later post.

You may will need to go into /etc/sysconfig/varnish  and set the listen port

3. Modify the Apache configuration to use 8080

All the advice points to updating /etc/httpd/conf/httpd.conf    but if you are running Virtualmin/Webmin stop – don’t do that.

You have to modify things via Virtualmin or you will get problems later.

It took a while to find

Virtualmin>[server]>Server Configuration>Change IP address and change the ‘New HTTP Port’ from 80 to 8080. Do this for every existing virtual server

If you have a lot, then you can do this at command level, I wrote this script that goes through all virtual server and changes the port to 8080

for dom in $(virtualmin list-domains –with-feature web –name-only); do
virtualmin modify-web –domain $dom –port 8080
done

 

You then just need to make sure that apache isn’t also listening on port 80.

Go to Webmin>Servers>Apache Webserver, scan down the list of existing Virtual Servers they should all be 8080, the switch to the Global configuration tab > Networking and Addresses, under ports if the is an entry with 80 remove it (none and blank) and save, port 80 shouldn’t be mentioned here at all.

4. Restart The Servers

Sounds simple. I tend to prefer stopping and starting servers at command level. You just need to make sure you stop apache, start varnish and then start apache

e.g.

service httpd stop

service varnish start

service httpd start

 

If httpd doesn’t start then its because it is still listening to post 80, or you didn’t change the varnish default.vcl from 80 to 8080

Check you sites are running!

You also might want to see if varnis is actually running and doing something – a couple of command line commands to run woudl be varnishlog and varnishstat. I might post a bit more about mnitoring when I get more familiar with it.

5. Tidy up Virtualmin server templates and make sure that Varnish runs on boot / restarted with Apache

When you create new virtual servers it uses a server template, and if you don’t change the values you will create new virtual servers on port 80 which will create issues.

Virtualmin>Server Templates> edit each template / template section = Apache website, change Port number for Virtual Hosts to 8080

You need to make sure that Varnish start on reboot too, so

Webmin>System>Bootup and Shutdown

scroll down to find Varnish, edit and set it to start on boot

And you will also need to ensure that Varnish is restarted after you restart Apache for any reason (well you may get away with not, but I think it is safer)

Webmin>Servers>Apache Webserver

follow the top link to module config and the pull down, system configuration  and modify the command to start Apache from  /etc/rc.d/init.d/httpd start    to /etc/rc.d/init.d/httpd start;/etc/init.d/varnish restart

and the same for the command to apply after configuration.

That should do it!

references / sources

In my voyage of discovery I referenced these items the most

http://blog.nexcess.net/2012/05/21/installing-varnish-for-your-magento-store-on-centos-6/  despite being about Magneto, this well written resource cover a lot of Centos setup in a simple and informative way. Watch out, don’t just cut and paste as this blog has converted quotes into html format.

https://www.varnish-cache.org/docs/3.0/ is the official Varnish documentation which is fine, but it doesn’t help too much beyond the basic setup, worth reading through

http://ocaoimh.ie/2011/08/09/speed-up-wordpress-with-apache-and-varnish/ this is a Ubuntu based post, focusing on WordPress and uses the local host sharing 80 port concept, this actually wasted a lot of time for me. I am also a bit suspect of the wordpress based vcl, but I did base my vcl on some of it.

https://www.varnish-cache.org/trac/wiki/VCLExamples  has VCL examples, and is a bteer place to get to understand the VCL options and there are some user contributed WordPress VCls which may be  a better way of going than the above.

[Next] Find out where to host WordPress [Read the full article…]

Filed Under: Linux, Tech Tips, Useful Stuff  Tagged: Cache, Centos, Magento, Varnish, Virtualmin, Webmin, Wordpress

About Alan

I'm Alan from Fullworks Digital Ltd, where I develop WordPress Plugins and support and manage WordPress websites.

My day job consists of solving clients' WordPress issues and developing new code and solutions.

I started as a professional programmer in 1979 and had been involved with the IT of business technology in virtually every area that exist.

Badlywired.com is my personal blog and my aide memoire of the many interesting facts that I come across. As I spend a lot of time gathering parts of solutions from the internet and assembling them into my own solutions, and also just learning how to do things, this blog is primarily my 'note book' and a way of giving something back to the online community that has helped me extensively.

Comments

  1. Martin says

    28th September 2013 at 3:50 pm

    Gee I wish I’d found this article a few days ago. Would have saved me the same grief since I’m not a SysAdmin 🙂
    Now to figur out why switching to fcgid in VirtualMin consumes twice the memory. Maybe I’ve got some double up running or something.
    Nice summary, mate

    Reply
    • Badly Wired says

      25th November 2013 at 10:54 am

      I have been thinking about the fcgid issue a lot too. It seems that you get a process forked for each php user. If you get some further thoughts please share them.

      I Impelemented OPCache on my servers (the replacement for APC), so at least the common PHP code is cached.

      Reply
  2. Guy says

    11th October 2013 at 10:48 am

    Hi there,

    Just wanted to say thank you for taking the time to write this up as I have been struggling.

    About to launch in and try again.

    Cheers

    Guy

    Reply
  3. Serhat says

    25th November 2013 at 10:24 am

    This is a great help, thanks for it. Just a side note for anyone using debian like me: the default configuration for varnish on debian is on /etc/default/varnish and not on /etc/sysconfig/varnish as on CentOs.

    Reply
    • Badly Wired says

      25th November 2013 at 10:51 am

      Thanks for you additional input. Yes, I operate my servers on Centos, so my articles are Centos centric. Hopefully your comments can help people on Debian.

      Reply
  4. Eddie says

    4th December 2013 at 6:19 pm

    Very useful, thank you!

    Why did you remove the virtualmin script to batch change the ports apache listens on?

    Reply
    • Badly Wired says

      4th December 2013 at 6:36 pm

      Hi Eddie. I don’t quite understand the question about the batch script, it is still there as far as I can see. Are you gee ting an issue viewing it? Please let me know.
      Alan

      Reply
  5. Eddie says

    4th December 2013 at 7:35 pm

    sorry, i got confused. the article which contains the script is /www.tienle.com/2013/10-08/setting-varnish-with-virtualmin-centos-5-steps.html

    i have multiple vhosts in different IPs in the same physical server. i’m trying to figure out the “backend default” syntax in default.vcl

    Reply
    • Badly Wired says

      9th December 2013 at 9:25 pm

      Thanks, cheeky that Tienle’s copied my blog word for word!!! they have added a little bit more abut benchmarking. As he stole my stuff do you think I should nick his?

      Reply
  6. SR says

    23rd January 2014 at 9:32 pm

    Was the article removed? I don’t see the 5 steps.

    Reply
    • Badly Wired says

      23rd January 2014 at 10:09 pm

      No the article is still there. If you look below the first paragraph you will see a box saying
      “to read all of this post we would really appreciate you liking socially with one of these buttons”

      If you facebook like or tweet or whatever the full article gets reveal. It is known as ‘pay with a like’, lot cheaper than paying with money 🙂

      Reply
  7. John Byrd says

    4th May 2015 at 2:50 pm

    Your HTML reformatter reformatted your virtualmin shell code example. Try instead:

    for dom in ($virtualmin list-domains –with-feature web –name-only); do
    virtualmin modify-web –domain $dom –port 8080
    done

    Reply
    • Alan says

      4th May 2015 at 3:13 pm

      Thanks. The ‘backticks’ do actually work in centos but your syntax is probably better as it should work on any bash shell. Although you made a typo in you ‘correction’. It should have the $ before the bracket (I’ll modify the code in the post)

      for dom in $(virtualmin list-domains –with-feature web –name-only); do
      virtualmin modify-web –domain $dom –port 8080
      done

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Applications
  • Cloud
    • General
    • Google Cloud
    • IaaS
    • Other Internet Hosted Applications
      • Wordpress
        • WooThemes Canvas
        • WooThemes Canvas CSS
    • SaaS
  • Code snippets
  • Discounts
  • Genesis
  • Google Apps for Works
  • Linux
  • News
  • SEO
  • Server setup
  • Services
  • Tech Tips
  • Uncategorised
  • Useful Images
  • Useful Stuff
  • WordPress Hosting
  • WordPress Plugins

Tags

background jobs beadcrumbs bind brandings Cache canvas Centos chrome css fail2ban Find firefox Flash fraud genesis gocardless godaddy Google google maps hackers internet explorer javascript KashFlow Linus linux Magento mapquest maps microsoft mysql news nohup php plugin plugins queens diamond jubilee replace SED SEO skype Varnish Virtualmin Webmin woothemes Wordpress

 

Affiliate and Privacy Notices

This site is free to use, but hopes to cover some costs through affiliate income, some products and links are affiliates and may earn the site advertising income.

Some affiliates use Cookies to track if you purchase from them, this allows them to apportion revenue to us you will need to refer to their specific privacy notices as to how you are tracked.

This site is a participant in the Amazon EU Associates Programme, an affiliate advertising programme designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.co.uk.

  • Privacy Policy

Copyright © 2021 · Badly Wired