Chinaunix首页 | 论坛 | 博客
  • 博客访问: 266801
  • 博文数量: 56
  • 博客积分: 1190
  • 博客等级: 少尉
  • 技术积分: 640
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-21 17:05
文章分类

全部博文(56)

文章存档

2014年(2)

2013年(4)

2012年(46)

2011年(4)

我的朋友

分类: LINUX

2012-04-08 19:38:13

 
Published on Sun, 2008-08-17 08:30

A Drupal site with several extra modules installed can leave quite a large memory footprint, especially when served through the beast that is Apache. Don't get me wrong, I think Apache is a great webserver and have used it for years without any real problems, but sometimes you need to squeeze a little more performance than Apache is willing to give.

I recently moved a lot of my Drupal sites over to a 500MB (which I would highly recommend). With only 500MB or RAM to play with, there is not much room for wastage and I found that Apache was just too much of a memory hog to be viable. So I turned to .

Nginx?

Nginx (pronounced "engine X" much to my surprise!) is a relatively new and little known about web server, written by a Russian by the name of . It's lightweight, fast, flexible, straight-forward to configure and is rapidly gaining popularity in the web world. Here are some facts about it (taken from ):

  • nginx has been running for more than three years on many heavily loaded Russian sites including ().
  • In March 2007 about 20% of all Russian virtual hosts were served or proxied by nginx.
  • According to Google Online Security Blog year ago nginx served or proxied about 4% of all Internet virtual hosts, although Netcraft showed a .

That's quite impressive. But what's more impressive is how it performs. I'm not running any particularly high traffic web sites, but I have definitely noticed a performance gain with all of my Drupal sites since I switched. And, for my situation where I have a relatively small amount of RAM to play with, Nginx wins hands down. Joe Williams did on his blog.

The guys over at Slicehost have already written some excellent articles about so I'm not going to cover that here. What I am going to do is share my Nginx virtual host configuration which works beautifully with Drupal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
server {
    listen   80;
    server_name  mydomain.com;
    rewrite ^/(.*) permanent;
}
   
server {
    listen 80;
    server_name
   
    access_log /path/to/mydomain.com/log/access.log;
    error_log /path/to/mydomain.com/log/error.log;
   
    root /path/to/drupal/root/;
    index index.php;
   
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1 last;
    }
   
    error_page 404 index.php;
   
    # hide protected files
    location ~* .(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$|^(code-style.pl|Entries.*|Repository|Root|Tag|Template)$ {
      deny all;
    }
   
    # hide backup_migrate files
    location ~* ^/files/backup_migrate {
      deny all;
    }
   
    # serve static files directly
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
        access_log        off;
        expires           30d;
    }  
   
    location ~ .php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
    }
}

This configuration does several things:

  • Forwards all requests for mydomain.com to
  • Installs an appropriate url rewrite confiruration for Drupal
  • Routes all requests for .php files through fastcgi
  • Serves static files directly
  • Protects important Drupal core files (normally done by .htaccess)
  • Protects directory used by the module (normally done by .htaccess)

Obviously you need to substitute the path names to make them correct for your own system.

I don't want to take credit for any of this as it was cobbled this together from several other resources, mainly from a thread on drupal.org entitled .

Comments Submitted by on Tue, 2011-04-12 20:09

Hello , I tryed to run a drupal site under an Apache + Fastcgi setup and i had two major problems .1. uypload was still by apache user ( www-data ) with permission 600 so after that only apache may read the file and not the user that run the site .the result was that server couldn't read the file2. chaos tools modules couldn't find the right path from file.inc file and the result was that it couldn't find the corect path to create the css fileafter that i returned to apache + boost module to have better cache and perfomance results. I tryed to find more help for my problems in apache  + fastcgi but i couldn't find in internet

阅读(1553) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~