The running WordPress blogs on a well known domain is slow, if you don’t optimize for speed. As the requests are going through the full LAMP stack, caching stuff is the first stop. Second I don’t use apache as primary delivery webserver, I use nginx to do this. I have chosen this setup as it provides lots of performance and there is no need to change anything in the existing WordPress installation. Even experienced WordPress users do not see the difference on the WordPress side.
From LAMP to NVA
Classical LAMP setup uses following apache config for a webserver with name based virtual hosts:
##### start ww.linuxpinguin.de Listen 80 NameVirtualHost 178.63.61.72:80 LogFormat ”%V %v %h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User−Agent}i\”” cvh <VirtualHost 178.63.61.72:80 > DocumentRoot /var/www/linuxpinguin.de ServerName www.linuxpinguin.de php_admin value open_basedir /var/www/linuxpinguin.de:/usr/share/php:/usr/share/pear ErrorLog /var/log/apache2/linuxpinguin.de/error.log CustomLog ”|/sbin/cronolog −−symlink /var/log/apache2/linuxpinguin.de/access.log /var/log/apache2/linuxpinguin.de/access.log %Y−%m” cvh </VirtualHost> ##### ende www.linuxpinguin.de
This is converted into the following apache config to fit into the NVA setup. As you see only the Listen port and the binding address have changed.
<VirtualHost 127.0.0.1:81> <Directory "/var/www/web5/web"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ServerName www.linuxpinguin.de ServerAlias www.linux-pinguin.de ServerAlias linux-pinguin.de ServerAlias linuxpinguin.de ServerAdmin webmaster@linuxpinguin.de DocumentRoot /var/www/web5/web ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log vhost_combined ServerAlias linuxpinguin.de www.linux-pinguin.de DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml index.cgi index.pl index.jsp Default.htm default.htm ScriptAlias /cgi-bin/ /var/www/web5/cgi-bin/ AddHandler cgi-script .cgi AddHandler cgi-script .pl ErrorLog /var/www/web5/log/error.log AddType application/x-httpd-php .php .php3 .php4 .php5 php_admin_flag safe_mode On php_admin value open_basedir /var/www/linuxpinguin.de:/usr/share/php:/usr/share/pear AddType text/html .shtml AddOutputFilter INCLUDES .shtml Alias /error/ "/var/www/web5/web/error/" ErrorDocument 400 /error/invalidSyntax.html ErrorDocument 401 /error/authorizationRequired.html ErrorDocument 403 /error/forbidden.html ErrorDocument 404 /error/fileNotFound.html ErrorDocument 405 /error/methodNotAllowed.html ErrorDocument 500 /error/internalServerError.html ErrorDocument 503 /error/overloaded.html AliasMatch ^/~([^/]+)(/(.*))? /var/www/web5/user/$1/web/$3 AliasMatch ^/users/([^/]+)(/(.*))? /var/www/web5/user/$1/web/$3 RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.linux-pinguin\.de [NC] RewriteRule ^/(.*) /$1 [L,R] RewriteCond %{HTTP_HOST} ^linux-pinguin\.de [NC] RewriteRule ^/(.*) /$1 [L,R] RewriteCond %{HTTP_HOST} ^linuxpinguin\.de [NC] RewriteRule ^/(.*) /$1 [L,R] </VirtualHost>
Now were do the request for 127.0.0.1:8080 are coming from? They come from our varnish caching daemon. Here is the smallest configuration for it:
backend default { host = ”localhost ”; port = ”8080”; # This need to be the same as the Apache vHost port listener ! }
varnish itself listens on 127.0.0.1 port 6081, so we now need to know where varnish gets its requests from? They are coming from the nginx webserver. This is the configuration of the nginx:
###### start linuxpinguin.de server { listen 80; # Default listen port server_name www.linuxpinguin.de linuxpinguin.de www.linux-pinguin.de linux-pinguin.de; access_log /var/log/apache2/linuxpinguin.de/access_log; gzip on; # Turn on gZip gzip_disable msie6; gzip_static on; gzip_comp_level 9; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; location / { proxy_redirect off; # Do not redirect this proxy - It needs to be pass-through proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Server-Address $server_addr; proxy_pass_header Set-Cookie; proxy_pass http://127.0.0.1:6081; # Pass all traffic through to Varnish } } ##### end linuxpinguin.de
A newer post about the subject in my web server talk.
why not use nginx with php-fpm and get rid of apache altogether?
i totally agree apache is not usefull…
If you remove Apache, then you might have trouble with WordPress plugins using custom htaccess rewrite rules. Then for every plugin (and every update) you need to convert the plugin’s htaccess rules into a proper Nginx configuration.
Until A) Nginx can read htaccess files and understand mod_rewrite with 100% accuracy…or B) plugin developers provide a Nginx include file … Apache is probably easier to work with WordPress websites.
@edward @web design
php-fpm is common with nginx, and is useful for hosting personal or client websites. it also performs fairly well. however, because it uses a ready access worker pool , in theory, it wouldn’t scale well in a scenario where you have a shared server with many many users on it-
on the other hand, apache has the fastcgid and suexec modules. in this case, the worker pool is inherently dynamic, and if tuned properly, can scale much further… thus, it can host many more websites per machine. this is also not to mention that it IS possible to fine tune Apache2 to behave like NGinx. you can’t just dump it out of the box and expect it to operate like a barebones server.
Apache2 is an industry standard for shared hosting environments. it also makes it a well tested appliance. It also has a plethora of modules and well tested addons. believe it or not, there IS an advantage to using Apache2 on the back end.
IMO, NGinX server one purpose, which Apache2 serves another. if anything, my question would be… why not use Varnish for caching HTTP requests, and NGinX for caching HTTPS. and skip the Varnish -> Nginx bit?