How to make Drupal 7 fast with Memcached + Varnish + Nginx + PHP-FPM on Ubuntu

Just in 40 minutes ago, i write article about using Memcached + Nginx + Php-fpm on Drupal 7. I wrote that articles in same time experimenting my development server ( yoodey.com ). I'm satisfhy with NGINX + Memcached and it change until i have thinking about combine it with Varnish. Yes, it sound crazy for me, but i think it is good way to deliver Drupal 7 in HIGH WAY!

So, the step is :
1. Memcached + Varnish + NGINX installation
you can go to my previous articles : Memcached + Nginx + Php-fpm on Drupal 7.

2. Change /etc/nginx/sites-available to works with Varnish
We should change NGINX 80 port into 8082.

<?php
server
{

       

listen   8082; ## listen for Varnish

       

server_name localhost;
       
root        /var/www/;
       
access_log  /var/log/nginx/drupal.access.log;

        if (!-

e $request_filename) {
               
rewrite ^/(.*)$ /index.php?q=$1 last;
        }

       

# if the file is not imagecached, create one
       
location ~ /files/imagecache/ {
               
rewrite ^/(.*)$ /index.php?q=$1 last;
        }

       

# just send a empty response if the favicon.ico is m.i.a
       
location = /favicon.ico {
               
try_files /favicon.ico =204;
        }

       

# hide protected files
       
location ~*.(.htaccess|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$ {
               
deny all;
        }

       

location / {
               
index  index.php index.html index.htm;
        }

       

location ~ \.php$ {
               
fastcgi_pass   127.0.0.1:9000;
               
fastcgi_index  index.php;
               
fastcgi_param  SCRIPT_FILENAME  /var/www/$fastcgi_script_name;
                include
fastcgi_params;
        }

        

location ~ /\.ht {
                
deny  all;
         }
}
?>

3. For Varnish installation, you can go to : How to Varnish + Drupal 7.

4. Restart Nginx & Varnish service by :
sudo service nginx restart
sudo service varnish restart

HTTP/1.1 200 OK
Server: nginx/0.7.67
Content-Type: text/html; charset=utf-8
X-Powered-By: PHP/5.3.3-1ubuntu9.3
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sat, 09 Apr 2011 19:28:16 +0000
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "1302377296"
X-Generator: Drupal 7 (http://drupal.org)
Content-Length: 9752
Date: Sat, 09 Apr 2011 19:28:16 GMT
X-Varnish: 570209332
Age: 0
Via: 1.1 varnish
Connection: keep-alive

Your Drupal7 now should fast than 127.0.0.1, ever!

Tags:



You should follow me here

Comments

I was browsing through your website just to see how was the response time. But I didnt see any performance improvement and it was too slow. Are you sure your configurations are correct? If you run even nginx alone with memcache, the response time is very fast. I guess the problem is you are allowing to run php for anonymous users. Thanks

I have upgrade my server in several day before and this may be affected yours. I tried test this page using browsermob.com ( http://browsermob.com/free-website-performance-test/5f7dcba289e3441999b3... ) and it gave me 1.96 seconds which i think this is fast enough.

Please test this page again and give me feedback if still give slow performance. Cheers

Varnish maybe serving you page, but according to those headers you are showing, Varnish is not serving a cached page.

Indeed, i don't use varnish right now because i give a try to NGINX + memcached. Also i have another python running in this server.

Also, Varnish is not serving a cached page is true and i will remember that :)

how did you set the permissions?

For nginx, you can set permission at nginx.conf

Hi, did you finish the deployment of varnish? I think the speed is still too low, I am now preparing a newsite either with joomla or drupal (which I don't have any experience before), thanks!

Sure, I finish and this site (Drupal) use Varnish and Apache2 ( because I need mod-wsgi to handle Django applications )

Here's what I get for http://yoodey.com/:
The Last-Modified header's value isn't a valid date.
This response is negotiated, but doesn't have an appropriate Vary header.
The response body is different when content negotiation happens.
During validation, the ETag didn't change, even though the response body did.

I'm using nginx - php-fpm with eaccelerator. Considering Varnish but you don't seem to be using it on this site so maybe its not that great.

Hi James, Thanks for correction.

Indeed, I'm not using Varnish because I recently move my site into new server, which I don't have much time to use same configuration with the past.

ah its not wordpress, its drupal right?

what a great post, just signed up to your RSS feed and hope to read more of your posts in the future. keep it up!

Add new comment