Why is apache much slower with naked domain?

October 20, 2018 374 views
Apache Ubuntu 16.04

I’m running a droplet with apache and wordpress installed on it.
Basic load testing with the ab tool shows that the requests per second are much lower when the naked domain is used.
For example:

ab -kc 10 -n 100 https://example.com/ 

results in an average connection time of >2000ms and

ab -kc 10 -n 100 https://www.example.com/ 

would result in an average connection time of ~700ms. Also htop shows that the cpu is at 100% for the test with the naked domain and for the www. domain the cpu stays relatively low all the time.

2 Answers

What’s your .htaccess look like? Is it perhaps redirecting in a loop until it hits the threshold and gives up? The apache error log will likely have some warning on this. I’d start there first.

The error log shows unfortunately nothing and the .htaccess only contains the standard wordpress entry.
However I have a suspicion that the problem is related to the WP Super Cache plugin.
The small droplet runs a relatively heavy wordpress site. For some reason the cached static content is not loaded when the naked domain is accessed, instead the dynamic PHP content is called for every request.
For now the problem is solved with following .htaccess rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Have another answer? Share your knowledge.