In my previous post I explained how to deploy a simple WordPress site using AWS. This post shows how to set up a custom domain to access your site. The default way to access EC2 instances is by typing its IP address (192.168.0.1) in a browser. This is great for testing, but when going public with your blog or portfolio website, it makes more sense to have a domain name such as "example.com" instead. You can learn more about DNS and IP addresses outside this post.
AWS Route53 is a web-based domain resolution service, packed with additional features for reliability and scalability. It's easy to use, flexible and great for beginners. However, this post is intended for those (like me) who do not wish to use Route53.
Step 1 - Set up Elastic IP
Navigate to EC2 > Network and Security > Elastic IPs on the AWS Management Console and click on allocate new address.
Click "Allocate" on the next screen. You'll see your newly created Elastic IP after confirming. Select this IP > Actions > Associate Address.
Select your instance from the dropdown and click Associate. You now have an elastic IP address for your EC2 instance. This means you have a static IP that doesn't change even after restarting the instance. This is important to complete our next step.
Verify that you can see your website by navigating to this elastic IP address.
Step 2 - Update your domain's DNS records to point to your elastic IP
Create type A DNS record for your domain, which points to your elastic IP. Without an elastic IP, we'd have to keep updating this record ever time you restart your AWS instance.
After you create a new DNS record it can take anywhere between 5 minutes to 1 hour, to update. ⏳
Step 3 - Update EC2 instance's domain settings
Login to your EC2 instance via SSH, then specify your domain name in apps/wordpress/htdocs/wp-config.php file like shown below.
Replace```define('WP_SITEURL',
'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
with```define('WP_SITEURL',
'http://DOMAIN/');
define('WP_HOME', 'http://DOMAIN/');
And that's about it. You should be able to access your WordPress site at your domain address. 🎉
Let me know what you thought about this article in the comments. I want to improve my writing and help others learn to love tech, the way I did.
Top comments (4)
This is fine if you just want to simply add a domain to your EC2 ip address.
But what about:
adding a SSL [CertManager], CloudFront, and a Application Load Balancer?
Plus you need to take care of any redirects http to https, no-www to www.
Hai,
I need to have Static HostName in Autoscaling of Instances and i need to maintain Static Ip also ..is it possible?
Tks for the post.
The link pdrcybersecurity.com/dns-request-t... is not working. I'm stuck on step 2, any advice?