ประสิทธิภาพ WordPress ของฉันและแคชสแต็ค
นี่เป็นสแต็กประสิทธิภาพ WordPress ที่ดีที่สุดสำหรับเซิร์ฟเวอร์เดี่ยวหรือระดับกลางถึงต่ำ ฉันจัดประเภทช่วงกลางเป็นแกนเดียวที่มีหน่วยความจำประมาณ 1G และไดรฟ์ที่รวดเร็วพอสมควร
เซิร์ฟเวอร์สแต็ก
- Linux - Debian Lenny หรือ Ubuntu
- Nginx - กำหนดค่าเป็นแคชแคชไฟล์แบบคงที่ของ proxy
- Apache - Apache จะจัดการ PHP ที่ถูกโหลดโดย Nginx บนพอร์ตอื่น
- MySql - ต้องการโดย WP ตรวจสอบให้แน่ใจว่าคุณใช้เวอร์ชันเสถียรล่าสุด
- PHP - เวอร์ชันเสถียรล่าสุดของ 5.2 หรือ 5.3 สาขา
PHP Cache
- APC - กำหนดค่าด้วยหน่วยความจำ mmap และขนาด shm อย่างน้อย 128M
WordPress ปลั๊กอินประสิทธิภาพสแต็ค
- ตัวรวมแคชพร็อกซี Nginx
- W3 Total Cache - ตั้งค่าแคชหน้าเป็นดิสก์ที่ได้รับการปรับปรุงลดขนาดดิสก์และวัตถุและ db เป็น APC
- Self Hosted CDN - สร้างนามแฝง 4 ชื่อที่ชี้ไปที่โดเมนบนเซิร์ฟเวอร์ตั้งค่าเพียงเพื่อให้บริการไฟล์คงที่  
 
ด้วย W3 Total Cache เรากำลังใช้ดิสก์สำหรับแคชของหน้าเว็บและย่อขนาดเนื่องจาก Nginx จะให้บริการไฟล์คงที่ของเราอย่างรวดเร็ว
วิธีกำหนดค่า Nginx เพื่อให้บริการไฟล์คงที่และส่งต่อ PHP ไปยัง Apache
ปัญหาของการใช้ Apache เพียงอย่างเดียวคือมันเปิดการเชื่อมต่อและพบ php ในทุก ๆ การร้องขอแม้แต่ไฟล์สแตติก สิ่งนี้เป็นการสูญเสียการเชื่อมต่อเนื่องจาก Apache จะเปิดไว้และเมื่อคุณมีการรับส่งข้อมูลจำนวนมากการเชื่อมต่อของคุณจะชะงักเนื่องจากไม่มีการใช้งาน
โดยค่าเริ่มต้น Apache จะรับฟังคำร้องขอที่พอร์ต 80 ซึ่งเป็นเว็บพอร์ตเริ่มต้น ก่อนอื่นเราจะทำการเปลี่ยนแปลงไฟล์ Apache และโฮสต์เสมือนของเราเพื่อฟังบนพอร์ต 8080
Apache Config
httpd.conf
ตั้ง KeepAlive เป็น off
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 จริงของผู้เยี่ยมชม หากไม่ใช่บันทึกของคุณจะมี 127.0.0.1 เป็นที่อยู่ IP ต้นทาง
กำหนดค่า Nginx
บน Debian คุณสามารถใช้ที่เก็บเพื่อติดตั้ง แต่มีเฉพาะรุ่น 0.6.33 ในการติดตั้งเวอร์ชันที่ใหม่กว่าคุณจะต้องเพิ่มแพ็คเกจแบ็กเอนนี่เลนนี่
$ 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
มันง่ายกว่าการรวบรวมจากแหล่งที่มา 
Conf Nginx และไฟล์เซิร์ฟเวอร์ config
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 ของคุณ ฉันต้องการใช้วิธีการเปิดใช้งานไซต์กับโฮสต์ v แต่ละตัวที่เชื่อมโยงกับไฟล์ในไดเรกทอรีที่มีไซต์
$ 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 conf (สำหรับเว็บไซต์หลายแห่งคุณจะต้องมีเพียงหนึ่ง vhost)
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;
        }
        }
conf CDN ที่โฮสต์ด้วยตนเอง
สำหรับ CDN ที่โฮสต์ด้วยตนเองของคุณจะต้องตั้งค่าให้บริการไฟล์คงที่โดยไม่ต้องผ่านพรอกซี
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 การตั้งค่านี้ในทางทฤษฎีสามารถให้บริการ 1833.56 คำขอต่อวินาที
$ ab -n 1000 -c 20 http://yoursite.com/
