mskw
mskw

Reputation: 10358

How can I have a AWS subdomain website point to another EC2 instance which hosts wordpress?

Here is the situation:

I have a static website hosted by AWS S3(www.mysite.com), however, I want to also attach a blog to a sub-path with in my domain (www.mysite.com/blog) which uses wordpress on an EC2 instance.

How would I go about it?

Upvotes: 1

Views: 901

Answers (2)

Michael - sqlbot
Michael - sqlbot

Reputation: 179384

Yes, this can be done, but you need to understand why the solution works the way it does.

A domain name points to a single logical endpoint, which handles all requests for the domain. If certain paths are handled by one system and other paths are handled by another one, then a single system must be in charge of routing those requests, and routing them through itself.

You cannot configure how paths are handled using DNS.

In my answer to Can I use CloudFront to serve a WordPress blog from the same domain, but a different server? (at Server Fault), I gave an overview of how this can be done in an AWS-centric solution. CloudFront, in addition to providing caching, is a reverse proxy, and that's fundamentally what you need, here: a reverse proxy to examine each request and select the correct back-end server. There are other solutions, such as using HAProxy in EC2 to handle request routing but they are more complex and may not perform as well in all cases.

You configure a CloudFront distribution with two origin servers (your bucket's web site endpoint and the Wordpress server), and use two cache behaviors so that /blog* goes to Wordpress and everything else goes to the bucket. Then you configure your domain name as an alternate domain name on the CloudFront distribution, and point your domain name to CloudFront in DNS.

The slightly tricky part here is that the wordpress site must be rooted at /blog and not at / because CloudFront will actually send the /blog (at the beginning of the path) to the WP machine, so it needs to expect that. CloudFront uses the path prefix to select the origin server (by finding the matching cache behavior for that path), but it can't remove the path prefix.¹

Wordpress is not my specialty, the this appears to require some WP configuration changes that appear to be fairly straightforward.


¹ CloudFront can't remove the path prefix. This will change when Lambda@Edge launches, which is an integration of CloudFront and Lambda functions, allowing server-side examination and manipulation of request and response headers from within the CloudFront infrastructure, but even when that is a available, it will still be advisable to configure WP to not be at the root, for simplicity.

Upvotes: 3

Karan Shah
Karan Shah

Reputation: 1324

By a different subdomain, I'm assuming that you want the blog to be at blog.mysite.com. I think that is the only way to go (you cannot use a /blog but will have to use a subdomain). In that case, following steps should work:

  1. Create an Elastic IP and attach it to the EC2 instance
  2. Configure the EC2 WP instance to respond to blog.mysite.com
  3. In the DNS provider of www.mysite.com, point the A record of blog to point to the Elastic IP of the EC2 instance

Upvotes: 2

Related Questions