Simply Fast WordPress [8] 1000x Faster WordPress Tuning – Nginx

Take a benchmark test with Nginx+HHVM configuration

Next, we will change the settings of the virtual host to display WordPress. Save the following code as "/etc/nginx/conf.d/http.conf". Remember to enter your own host name after server_name.

server {
        listen 80;
        server_name ec2-xxx.xxx.compute.amazonaws.com;
        root  /var/www/html;
        index index.php index.html index.htm;            
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~* /\. {
                  deny all;
          }
          location ~ [^/]\.php(/|$) {
                  fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                  if (!-f $document_root$fastcgi_script_name) {
                                  return 404;
                  }
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
          }
  }

Restart Nginx.

[root@ip ~]# systemctl restart nginx

Nginx+HHVM has been configured. Refresh your browser to see the WordPress front page and check the page load time with Firebug. In my environment it was about 16ms. As I mentioned before, this is about the limit we can achieve.

Perform a benchmark test with ab.

[root@ip ~]# ab -n 300 -c 30 http://ec2-xxx.xxx.compute.amazonaws.com/

In my environment, requests per second was 205.20. This is several percent better performance than the Apache+HHVM configuration.

Just for reference, let's perform a benchmark with the Nginx+PHP 7 configuration.

[root@ip ~]# systemctl disable hhvm
[root@ip ~]# systemctl stop hhvm
[root@ip ~]# systemctl enable php-fpm
[root@ip ~]# systemctl start php-fpm
[root@ip ~]# ab -n 300 -c 30 http://ec2-xxx.xxx.compute.amazonaws.com/

In this case the page load time is the same 16ms but the requests per second is down to 151.07. Even so, we can see the performance has improved by replacing Apache with Nginx.

Tuning contents Page load time Requests per second
Default environment 176ms 11.24
APC 70ms (251%) 29.20
OPcache+APCu 66ms (266%) 30.51
MariaDB settings 64ms (275%) 31.82
Translation accelerator (cache) 53ms (332%) 39.29
Translation accelerator (disabled) 36ms (488%) 56.78
gzip 35ms (502%)
Tuned settings 34ms (517%) 58.47
event MPM+php-fpm 33ms (537%) 60.79
AWS users 31ms (567%) 71.76
PHP 5.6+OPCache+APCu 32ms (550%) 61.84 (550.2%)
PHP 7+OPCache+APCu 18ms (977.7%) 148.08 (1250.6%)
HHVM 16ms (1100%) 195.05 (1690.8%)
Nginx+PHP 7 16ms (1100%) 151.07 (1344%)
Nginx+HHVM 16ms (1100%) 205.20 (1825.6%)

With this tuning we have increased the speed 18.2x the default environment.

We are at the climax of 1000x faster WordPress tuning. Next time, we will enabled page caching with the WordPress plugin WP SiteManager to get 228x faster.

[Previous article] [Next article]