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.
First add your domain to Route 53 and create the DNS zone for it.
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.
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.
Create an SSL certificate for your domain using AWS Certificate Manager.
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.
Change your A record in Route 53 as an Alias and chose the ELB setup previously.
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:
define('WP_SITEURL', 'https://domain.com/blog/'); define('WP_HOME', 'https://domain.com/blog/');
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.
Become an entrepreneur and launch your own store with my course How to Build an Online Store with WooCommerce and WordPress.