Simply Fast WordPress [10] 1000x Faster WordPress Tuning – Nginx FastCGI

This is a series of articles explaining how to speed up WordPress, the use of which is growing rapidly for CMS-based business sites and media sites. In the next few articles, I will offer techniques to tune WordPress’ speed by 1000x. --Kengyu Nakamura, Prime Strategy Co., Ltd.

In the previous article, we set up page caching using WP SiteManager, and speed up WordPress 228x the default environment.

In this article, we are going to put the finishing touches on 1000x faster WordPress tuning. With Nginx's FastCGI cache, we will continue tuning to 1127x.

WordPress Japanese version
WordPress Japanese version

This technique continues from previous tuning, so please refer to earlier articles to get to this point.

Install Nginx's FastCGI cache

Let's get ready to finish our tuning. This time we will be installing the page caching middleware, FastCGI, developed by Nginx.

FastCGI case example site

In order to use this feature, you must enable permalinks in WordPress. Go to the Dashboard, click on "Settings", then "Permalinks", select "Day and name" and save.

Return to the console and edit Nginx's settings file. Modify "/etc/nginx/nginx.conf" in the following manner:

  1. 1. (omitted)
    2. http {
    3. include /etc/nginx/mime.types;
    4. default_type application/octet-stream;
    5. log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
    6. '$status $body_bytes_sent "$http_referer" '
    7. '"$http_user_agent" "$http_x_forwarded_for"';
    8. access_log /var/log/nginx/access.log  main;
    9. sendfile on;
    10. #tcp_nopush     on;
    11. keepalive_timeout  3;
    12. gzip  on;
    13. server_names_hash_bucket_size 128;
    14. fastcgi_cache_path /var/cache/nginx/wordpress levels=1:2 keys_zone=wpcache:30m max_size=512M inactive=600m;
    15. include /etc/nginx/conf.d/*.conf;
    16. }

[Line 14 is modified]

Then, add the basic cache conditions to "/etc/nginx/conf.d/http.conf":

1. (omitted)
2. location ~ [^/]\.php(/|$) {
3. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
4. if (!-f $document_root$fastcgi_script_name) {
5. return 404;
6. }
7. fastcgi_pass 127.0.0.1:9000;
8. fastcgi_index index.php;
9. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
10. include fastcgi_params;
11. set $do_not_cache 0;
12.
13. if ($request_method = POST) {
14. set $do_not_cache 1;
15. }
16. if ($query_string != "") {
17. set $do_not_cache 1;
18. }
19. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
20. set $do_not_cache 1;
21. }
22. if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
23. set $do_not_cache 1;
24. }
25. fastcgi_cache        wpcache;
26. fastcgi_cache_key    "$request_method:$scheme://$host$request_uri";
27. fastcgi_cache_valid  200 60m;
28. fastcgi_no_cache     $do_not_cache;
29. fastcgi_cache_bypass $do_not_cache;
30. add_header X-F-Cache $upstream_cache_status;
31. }
32. (omitted)

[Lines 11-30 are modified]