Apache or Nginx, what softwares should be used to for your server to achieve the maximum performance? If you have a small free server from GCP from part 1, and you want it to be able to handle average 1000 clients per second, Nginx is the best option. Apache use more server resources and must be configured properly to get the best performance. Nginx can handle very large amount of traffic even in a limited environment. We have done the loading test with the server from Google Cloud Platform from part 1 and the result was great without deep optimization. 1000 client/sec is not the maximum that this setup can get, it is the limit of the free test we could get. When we tried the same test using Apache, the test was aborted at the beginning because server crashed. That is why we will use Nginx. We are not the server expert, so we will not discuss how to optimize Apache to pass the same test. What we will need is NGINX + MySQL + PHP-FPM + Microcaching + WordPress.
With Microcaching, Nginx can handle large amount of traffic because dynamic inquiries/files are cached to prevent overloading your database. For example if each client to your website generate 2 database inquiry, 1000 client will have 2000 inquires. If you set up cache for 5 seconds, 1000 clients within 5 seconds will only hit your database 2 times if both inquires are cached. That is the magic of this setup.
1 2 3
# always backup the file you want to change sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak sudo nano /etc/nginx/sites-available/default
Add the following to the file. You can add this before the server {} block
Add the following to location ~ \.php$ {} block. Below configuration will set the cache to expire after 10 seconds, and no cache for logged in users and commenters. You can change the 10s to longer time, but 10s is long enough for your need.
#Don't cache logged in users or commenters if ( $http_cookie ~* "comment_author_wordpress_(?!test_cookie)wp-postpass_" ) { set $no_cache 1; }
#Don't cache the following URLs if ($request_uri ~* "/(wp-admin/wp-login.php)") { set $no_cache 1; }
#matches keys_zone in fastcgi_cache_path fastcgi_cache qualityology-com;
#don't serve pages defined earlier fastcgi_cache_bypass $no_cache;
#don't cache pages defined earlier fastcgi_no_cache $no_cache;
#defines the default cache time fastcgi_cache_valid any 10s;
#unsure what the impacts of this variable is fastcgi_max_temp_file_size 2M;
#Use stale cache items while updating in the background fastcgi_cache_use_stale updating error timeout invalid_header http_500; fastcgi_cache_lock on; fastcgi_cache_lock_timeout 10s;
Comments