Virtualmin with Varnish and Drupal

10 posts / 0 new
Last post
#1 Sat, 12/17/2011 - 18:51
Mister

Virtualmin with Varnish and Drupal

Hi,

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 mydomain.com , it loads from Apache (port 80), the website works fine.

However, when I type mydomain.com:8080 , 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 127.0.0.1:80" 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 127.0.0.1. 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!

Sun, 12/18/2011 - 05:14
John_B

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 127.0.0.1 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 127.0.0.1 does work. What fails is connecting to a Drupal site on an Apache virtual server on 127.0.0.1: 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 http://www.virtualmin.com/node/20448

Sun, 12/18/2011 - 08:13 (Reply to #2)
Mister

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 88.22.266.340:80. 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/mysite.com.conf

and change the first line to VirtualHost 88.22.266.340:80. That's all that was missing.

Then when I typed in the adress bar mysite.com:8080 , 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

Wed, 09/17/2014 - 17:29 (Reply to #3)
pagio

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:

NameVirtualHost 127.0.0.1:8080

Listen 127.0.0.1:8080

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

VirtualHost 127.0.0.1:8080

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:

varnishstat

sources:

1. https://www.digitalocean.com/community/tutorials/how-to-install-and-conf...

2. https://www.digitalocean.com/community/tutorials/how-to-configure-varnis...

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

Sun, 12/18/2011 - 11:50
John_B

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 :-)

Sun, 12/18/2011 - 13:39
Mister

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

Sun, 12/18/2011 - 14:56
John_B

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.

Tue, 11/06/2012 - 06:32
eddieb

+1 for better Varnish integration.

PS: comment http://www.virtualmin.com/node/20486#comment-107817 is SPAM.

Sun, 06/16/2013 - 23:32
snlnz

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

Sat, 11/23/2013 - 03:05
eddieb

+1 for Varnish integration

Topic locked