Virtualmin with Varnish and Drupal


I’ve installed Virtualmin on Ubuntu 10.04 and it’s very useful.

I’ve installed one drupal site so far in which I enabled the Varnish module, and added the required lines to Settings.php.

I am trying to make Varnish work with it.

For testing, I left Apache on port 80, and told Varnish to listen on port 8080.

So when I type , it loads from Apache (port 80), the website works fine.

However, when I type , it should go through varnish and I get the page :

"It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet."

In varnish settings I set the backend to “localhost” which is the default. So I believe the problem is that the virtual server that I created in Virtualmin has an internal adress different than How can I edit in Virtualmin the internal adress of the virtual server to make varnish work?
Or should I set virtualmin proxy settings to “yes”?

thanks a lot for your help!

this post is not entirely clear to me as I am not sure whether you mean in Varnish settings the Drupal Varnish module or the .vcl file.

Have you set up varnish configuaration file ? (Debian path /etc/default/varnish, plus .vcl if that is the option you are using in varnish file )? Or maybe you are starting Varnish from cli.

I have had a lot of trouble getting Varnish to connect to an Apache backend on and after hours of thought and various posts on forums I have never understood what it is about my apache config on both cPanel and Virtualmin servers I have run which is not permitting that. But entering the server’s ‘external’ IP on which Apache is lisetning in your Varnish config at /etc/default/varnish (or in the .vcl file referenced there, if you are using one) does work for me. I also enter the server’s external IP in Drupal’s settings.php IP array for reverse proxy.

Setting control terminal address to does work. What fails is connecting to a Drupal site on an Apache virtual server on for this you need the external IP address. If that works for you, maybe you will be able to work out the reason and tell me!

See also my quick Varnish tutorial at the latest post in

Thanks for the reply, I actually read your post several times, and you are right that it’s better to stick with Varnish 2.1.

In Drupal I left the default Varnish settings.

I didn’t change the default Apache settings that Virtualmin set.

I installed Varnish 2.1 and asked to listen to port 8080, and set the backend at I used the vcl file from Lullabot but adapted for a single server use case. All Varnish configuration changes I made was in etc/default/varnish and in the vcl file.

To make it work, I had to edit in etc/apache2/sites-available/

and change the first line to VirtualHost That’s all that was missing.

Then when I typed in the adress bar , the site loaded fine and I could navigate it.

Now I thought the best solution in this situation was to leave Apache on port 80 and add a rule in iptables to redirect to port 8080 incoming traffic. Like this I don’t have to mess with Apache and Virtualmin settings. But this did not work so I will now put varnish on port 80 and apache on 8080

In cPanel when you change the port on which Apache listens (under ‘tweak settings’ in whm), all the viritual hosts are automatically rewritten in the auto-generated httpd.conf to the new port settings. It seems with Virtualmin that one needs to edit each virtual server individually, though it could be scripted with sed or something of that kind, and probably with the Virtualmin Pro cli tool, which I have not used.

Even after changing Website Template, I have found virtualmin adding a directive for Apache to listen on port 80 which you have to manually delete before Apache will start. You quickly notice if this has happened, as Apache will not start on port 80 if Varnish is on Port 80 : the opposite is not true. Maybe I did something wrong to cause Virtualmin to constantly do this.

A little tweaking to Virtualmin would improve Varnish integration, but as is, it is not too difficult to do. One downside of Varnish for small servers is that it is said it does not work well on 32 bit, though I never tried. But it is a fantastic tool.+

One other hint: if you are getting zero hits with a website, it is sometimes because you logged in, logged out, and the browser is stilll sending cookes which are not removed by the VCL. Clear cache, run varnishstat in a shell window, reload the site in a browser a few times, and watch the hit rate ratio climb :slight_smile:

I think I messed up the iptables. Could you post your iptables please?

I have this:

iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Best just reset firewall! Not sure my file will really help, it is the default which I get when I hit reset button, nothing else.

+1 for better Varnish integration.

PS: comment is SPAM.

It would definitely be good to see Varnish/Redis/APC integration.

+1 for Varnish integration

Once you have both apache and varnish installed, you can start to configure them to ease the load on your server from future visitors.

Varnish will serve the content on port 80, while fetching it from apache which will run on port 8080.

However the default settings for apache are still on port 80.

Change the port number for both the NameVirtualHost and the Listen line to port 8080, and the virtual host should only be accessible from the localhost. The configuration should look like this:



The Virtual Hosts should also be set to port 8080, and updated lines looks like this:


Save and exit the file and proceed to restart Apache and Varnish to make the changes effective.

service apache2 restart
service varnish restart

Accessing your domain should instantly take you to the varnish cached version, and you can see the details of varnish’s workings with this command:





ps. feed-it-back if it works :slight_smile: