Multiple sites on a single server

Every now and then someone asks me how I’ve got blogs setup on my servers.

As such, I’ve decided to create this post that documents my setup and why I made some of the decisions I did.

High Level Overview

All my sites are hosted on Amazon AWS LightSail servers. I didn’t use one of the pre-built blueprints as I’m very familiar with Linux, Apache web server (httpd), and WordPress.

WordPress Installs

Each blog is in it’s own sub-directory off of a common directory.For the purposes of this post, we’ll call it ‘/var/webcontent’. For example, this blog would be in ‘/var/webcontent/geekyramblings’.

Within each blogs sub-directory there is a html and log directory. The html directory contains the wordpress install and, as you might guess, the log directory contains the web server logs.

Database

Because of the relatively limited amount of memory in the Lightsail instance, I have a totally separate instance that just runs a MySQL database server. All the blogs (and a few other applications) use this database server.

I could have used a LightSail hosted database, but because of my previous experiences, I decided not to.

Apache

In the Apache httpd server configuration, I added the following line at the very end of /etc/httpd/conf/httpd.conf.

IncludeOptional sites/*.conf

This causes the httpd server to include all files in the sites directory, that end in .conf, to be included in the configuration.

The site specific configuration file for this blog is called geekyramblings.conf.

sites/geekyramblings.conf

<VirtualHost *:80>
ServerName www.geekyramblings.net
ServerAlias  geekyramblings.net 
Include sites/geekyramblings.inc

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.geekyramblings.net [OR]
RewriteCond %{SERVER_NAME} =geekyramblings.net 
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost> 

This configuration file establishes the virtual server, sets the site name & alias, includes the common site configuration.

Because I’m using SSL on my blog, it also sets up redirects so any visitors are automatically switched to the https version of the site.

sites/geekyramblings.inc

ServerAdmin david@midrange.com
DocumentRoot /var/webcontent/geekyramblings/html
Options FollowSymLinks Indexes MultiViews SymLinksIfOwnerMatch
ErrorLog /var/webcontent/geekyramblings/logs/error_log
CustomLog /var/webcontent/geekyramblings/logs/access_log combined
HostNameLookups on

<files xmlrpc.php>
order deny,allow 
deny from all 
</files>

<directory "/var/webcontent/geekyramblings/html">
Require all granted 
AllowOverride All 
</directory>

The block of xmlrpc.php is to prevent hackers from attacking my site. If you use the moble app to manage your site, you may need to allow xmlrpc.php to be accessed.

LetsEncrypt

As I mentioned, above, all my sites support https with certificates issued by LetsEncrypt.

I use the EFF’s certbot-auto client to create the certificates.

Certbot-auto has a nice capability to automatically configure httpd to use the SSL certificates. When certbot-auto modifies the httpd configuration, it creates a new .conf file with the certificate information. The file is name (for example) geekyramblings-le-ssl.conf. This is why I have the core virtual server configuration in a separate configuration file (.inc). I can maintain the common configuration information without having to worry about certbot-auto’s modifications.

Why Not Multi-Site?

WordPress has a feature that allows you to host multiple blogs on a single install. It’s called WordPress Multi-site.

While this may appear to be a nice fit for what I’m doing, there are issues that are somewhat difficult to resolve. Specifically, using SSL certificates.

SSL certificates are tied to domain names. While you can attach multiple domain names to a single certificate, and you can also create SSL certificates with wildcard domains (*.domain.com), it’s not easy to maintain multiple unique domain names with SSL certificates.

There are ways around this using proxies or 3rd party services, but that starts getting much more complex.

Another reason that I chose not to use multi-site is that different blogs are run by different people. In addition to my own blogs, I host my wife’s blog, my nephew’s blog, etc. Each blog has it’s own set of plug-in’s, themes, and settings.

It’s also easier to move the blog from one system to another if I see the need. I just dump the database, copy the wordpress install to the new system, and restore the database.

Leave a Reply

Your email address will not be published. Required fields are marked *