How to Host WordPress in a Subdirectory on Another Server with ServerPilot and AWS

host wordpress subdirectory aws aws | dns | hosting

If you want to host your blog or another app in a subdirectory on the same domain but a different server and make sure your servers are not affected by each other either by traffic spikes, errors or anything that might come up this is the setup for you. This is something I wanted to do for some time but didn’t get the chance to do it so the other I started looking for information on how to achieve this.

For this setup I’ve used AWS services and ServerPilot.io as a control panel, the setup is domain.com as Server1 and domain.com/blog as Server2. Probably you can achieve this with other services as the important things are the DNS setup and the Load Balancer rules.

*This tutorial might be a bit challenging if you don’t have a little experience with Amazon Web Services.

What I’ve used for the setup:

  • 2 EC2 Ubuntu instances – one for my main app and the other for my WordPress blog.
  • 2 Elastic IP’s.
  • One Aplication Load Balancer.
  • Route 53 DNS services.
  • AWS Certificate manager for SSL.
  • For ServerPilot.io I am using one account with 2 economy servers each with one app.

In my AWS account I already had setup an VPC and a security group that allows me to connect to the servers and also allows the connection with ServerPilot.

Step 1

First add your domain to Route 53 and create the DNS zone for it.

Step 2

Create your your  EC2 Ubuntu Instances and assign each of them an Elastic IP. I’ve used the N.Virginia region and both instances in the same availability zone but you can chose a different zone for more reliability.

Step 3

Add the EC2 instances to your ServerPilot account and add for each an app, the domain for both is the same: domain.com. Do not enable the ssl on the instances.

Step 4

Create an SSL certificate for your domain using AWS Certificate Manager.

Step 5

Create your ELB as an Application Load Balancer using the SSL and  this path based routing tutorial and setup Target Groups and the Listener rules. Redirect http traffic to https using this rule here. I’ve setup 2 Target Groups each with one instance and used the path rules to redirect traffic to the WordPress instance first.

Step 6

Change your A record in Route 53 as an Alias and chose the ELB setup previously.

Step 7

On the Server2 I’ve setup the app as a WordPress blog, log in the instance, go to the public folder and create a new folder called blog and move all the WordPress files in this folder.

Edit the wp-config file and these lines:

[php]

define(‘WP_SITEURL’, ‘https://domain.com/blog/’);
define(‘WP_HOME’, ‘https://domain.com/blog/’);

[/php]

 

That’s it, now you can test and everything should work great. Let me know if I can help or something doesn’t work properly.

If You enjoyed This Article Join My NewsletterCasual Wednesday

One email per week with interesting things I’ve read or found, plus new articles.