WordPressのパフォーマンスとキャッシュスタック
これは、低〜中規模の単一サーバーまたはVPSに最適なWordPressパフォーマンススタックです。私は、ミッドレンジを約1Gのメモリとかなり高速なドライブを備えたシングルコアとして分類しています。
サーバースタック
- Linux-Debian LennyまたはUbuntuのいずれか
 
- Nginx-リバースプロキシ静的ファイルキャッシュとして構成
 
- Apache-Apacheは、代替ポートでNginxによってオフロードされたPHPを処理します
 
- MySql-WPで必要です。最新の安定バージョンを実行していることを確認してください
 
- PHP-5.2または5.3ブランチの最新の安定バージョン
 
PHPキャッシュ
- APC-mmapメモリと少なくとも128Mのshmサイズで構成します
 
WordPressパフォーマンスプラグインスタック
W3 Total Cacheでは、Nginxが静的ファイルを非常に高速に提供するため、ページキャッシュと縮小にディスクを使用しています。
Nginxを設定して静的ファイルを提供し、PHPをApacheに渡す方法
Apacheを単独で使用する場合の問題は、接続が開かれ、静的ファイルであってもすべてのリクエストでphpにヒットすることです。これは、Apacheが接続を開いたままにして、接続が使用されていない場合でも接続が行き詰まるため、接続を無駄にします。
デフォルトでは、ApacheはデフォルトのWebポートであるポート80でリクエストをリッスンします。まず、ポート8080でリッスンするように、Apache confおよび仮想ホストファイルを変更します。
Apache Config
httpd.conf
KeepAliveをオフに設定します
ports.conf
NameVirtualHost *:8080
Listen 8080
サイトごとの仮想ホスト
<VirtualHost 127.0.0.1:8080>
     ServerAdmin info@yoursite.com
     ServerName yoursite.com
     ServerAlias www.yoursite.com
     DocumentRoot /srv/www/yoursite.com/public_html/
     ErrorLog /srv/www/yoursite.com/logs/error.log
     CustomLog /srv/www/yoursite.com/logs/access.log combined
</VirtualHost>
また、mod_rpafをインストールして、ログに訪問者の実際のIPアドレスが含まれるようにする必要があります。そうでない場合、ログの発信元IPアドレスは127.0.0.1になります。
Nginx Config
Debianでは、リポジトリを使用してインストールできますが、バージョン0.6.33のみが含まれています。新しいバージョンをインストールするには、lenny backportsパッケージを追加する必要があります
$ nano  /etc/apt/sources.list
この行をファイルに追加します deb http://www.backports.org/debian lenny-backports main
$ nano /etc/apt/preferences
ファイルに次を追加します。
Package: nginx
Pin: release a=lenny-backports 
Pin-Priority: 999
次のコマンドを発行して、backports.orgからキーをインポートし、パッケージを検証してシステムのパッケージデータベースを更新します。
$ wget -O - http://backports.org/debian/archive.key | apt-key add -
$ apt-get update
apt-getでインストールする
apt-get install nginx
これは、ソースからコンパイルするよりもはるかに簡単です。 
Nginx confおよびサーバーファイルの構成
nginx.conf
user www-data;
worker_processes  4;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    access_log  /var/log/nginx/access.log;
    client_body_temp_path /var/lib/nginx/body 1 2;
    gzip_buffers 32 8k;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
    gzip  on;
  gzip_comp_level   6;
  gzip_http_version 1.0;
  gzip_min_length   0;
  gzip_types        text/html text/css image/x-icon
        application/x-javascript application/javascript text/javascript application/atom+xml application/xml ;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
次に、Nginx仮想ホスティングをセットアップする必要があります。私は、sites-availableディレクトリのファイルにリンクされた各v host symで、sites-enabledメソッドを使用したいと思います。
$ mkdir /etc/nginx/sites-available  
$ mkdir /etc/nginx/sites-enabled
$ touch /etc/nginx/sites-available/yourservername.conf
$ touch /etc/nginx/sites-available/default.conf
$ ln -s  /etc/nginx/sites-available /etc/nginx/sites-enabled
$ nano /etc/nginx/sites-enabled/default.conf
default.conf
注意:  
次のファイルの静的キャッシュ設定は、Nginxプロキシキャッシュインテグレータープラグインが有効になっている場合にのみ機能します。 
proxy_cache_path  /var/lib/nginx/cache  levels=1:2   keys_zone=staticfilecache:180m  max_size=500m;
proxy_temp_path /var/lib/nginx/proxy;
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_send_timeout 120;
#IMPORTANT - this sets the basic cache key that's used in the static file cache.
proxy_cache_key "$scheme://$host$request_uri";
upstream wordpressapache {
        #The upstream apache server. You can have many of these and weight them accordingly,
        #allowing nginx to function as a caching load balancer 
        server 127.0.0.1:8080 weight=1 fail_timeout=120s;
}
WordPressサイトの設定ごと(マルチサイトの場合、必要なのは1つの仮想ホストのみ)
server {
        #Only cache 200 responses, and for a default of 20 minutes.
        proxy_cache_valid 200 20m;
        #Listen to your public IP
        listen 80;
        #Probably not needed, as the proxy will pass back the host in "proxy_set_header"
        server_name www.yoursite.com yoursite.com;
        access_log /var/log/nginx/yoursite.proxied.log;  
        # "combined" matches apache's concept of "combined". Neat.
        access_log  /var/log/apache2/nginx-access.log combined;
        # Set the real IP.
        proxy_set_header X-Real-IP  $remote_addr;
        # Set the hostname
        proxy_set_header Host $host;
        #Set the forwarded-for header.
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        location / {
                        # If logged in, don't cache.
                        if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
                                set $do_not_cache 1;
                        }
                        proxy_cache_key "$scheme://$host$request_uri $do_not_cache";
                        proxy_cache staticfilecache;
                        proxy_pass http://wordpressapache;
        }
        location ~* wp\-.*\.php|wp\-admin {
                        # Don't static file cache admin-looking things.
                        proxy_pass http://wordpressapache;
        }
        location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
                        # Cache static-looking files for 120 minutes, setting a 10 day expiry time in the HTTP header,
                        # whether logged in or not (may be too heavy-handed).
                        proxy_cache_valid 200 120m;
                        expires 864000;
                        proxy_pass http://wordpressapache;
                        proxy_cache staticfilecache;
        }
        location ~* \/[^\/]+\/(feed|\.xml)\/? {
 # Cache RSS looking feeds for 45 minutes unless logged in.
                        if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
                                set $do_not_cache 1;
                        }
                        proxy_cache_key "$scheme://$host$request_uri $do_not_cache";
                        proxy_cache_valid 200 45m;
                        proxy_cache staticfilecache;
                        proxy_pass http://wordpressapache;
        }
        location = /50x.html {
                root   /var/www/nginx-default;
        }
        # No access to .htaccess files.
        location ~ /\.ht {
                deny  all;
        }
        }
自己ホスト型CDN conf
自己ホスト型CDN confの場合、プロキシパスなしで静的ファイルを提供するように設定するだけです。
server {
        proxy_cache_valid 200 20m;
        listen 80;
        server_name yourcdndomain.com;
        access_log   /srv/www/yourcdndomain.com/logs/access.log;
        root   /srv/www/yourcdndomain.com/public_html/;
 proxy_set_header X-Real-IP  $remote_addr;
      location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
                                # Cache static-looking files for 120 minutes, setting a 10 day expiry time in the HTTP header,
                                # whether logged in or not (may be too heavy-handed).
                                proxy_cache_valid 200 120m;
                        expires 7776000;
                        proxy_cache staticfilecache;
                }
location = /50x.html {
                root   /var/www/nginx-default;
        }
 # No access to .htaccess files.
        location ~ /\.ht {
          deny  all;
        }
    }
サーバーを起動します
$ /etc/init.d/apache2 restart  
$/etc/init.d/nginx start
ベンチマーク結果
Apache Benchでは、このセットアップは理論的には1秒あたり1833.56リクエストを処理できます
$ ab -n 1000 -c 20 http://yoursite.com/
