AWS LightSail – Custom Domain and SSL Setup

Introduction

Previously, I’ve written about Amazon LightSail, a Virtual Private Server (VPS) offering, built on top of secure, reliable, and scalable AWS infrastructure. If you are new LightSail, I’ll recommend to read the previous post, as we will be building on top of that learning.

In the previous post, we covered the VPS basics, a little bit of AWS Lightsail introduction and few of its use cases. As part of that learning, we also demo installing and spinning up a WordPress website and we were able to access it using its dynamic public IP address.

In this post, we will take one step further and see how we can associate a custom domain and setup SSL for our WordPress website running on Lightsail.

I’ve bought a custom domain (mgarh.pk) from an external domain provider, you can use any provider and in most cases they all work in sort of similar way, select whichever provider you prefer to buy a domain name. So, I’ll be using mgarh.pk domain and will associate it with the WordPress website running on Lightsail server.

Following are the topics we will cover in this post:

  • Create a public Static IP Address for Lightsail instance.
  • Create a DNS Zone.
  • Associate DNS Zone and public Static IP Address.
  • Configure Nameservers for custom domain.
  • Enable HTTPs on Lightsail WordPress server .

Static IP Address

In previous post, we saw that we can access the WordPress website using its dynamic public address:

However, Dynamic public IP addresses attached to our LightSail instance will change whenever we start/restart the instance. This is of course not useful for our requirement. We need a static IP address, which doesn’t change with instance state and we will associate it to a custom domain in later step.

We can easily create and attach a public static IP address to our instance from Lightsail console by click of a button. Following picture shows the public static IP address created and attached to our instance:

Once a static IP address is setup, it will remain unchanged even we start/restart our instance.

Create DNS Zone

To use our registered domain with Lightsail, we can create a DNS Zone from the Networking tab on the dashboard:

this will ask for basic information such as domain name etc. as shown below:

so here I’ve entered the domain name and click create button and that’s it, DNS zone is created as shown below:

Take a note of Name servers, as these are the DNS records we’ll need to update with our domain provider (more on this later).

So far, we have create a Static IP address and also created a DNS zone, but they are yet not connected and we can connect these two pieces by adding DNS records. Following diagram illustrate this association:

Adding DNS Records

We can easily add DNS records for DNS Zone from the LightSail console. We’ll add two records, which both will resolve to the static IP address of Lightsail instance, we setup earlier:

and second DNS record as shown below:

With this, we are mostly done with the setup on the AWS Lightsail side for custom domain. Next, we will see how to add Name Servers to our domain provider side of the things.

Configure Name Servers for Custom domain

This process require us to visit the website of our domain provider and update the name servers with the values provided earlier when created the DNS zone. Following diagram illustrate this association:

Now, the exact user interface process will differ from provider to provider. Following picture shows the User interface which allows me to update the Name Servers records on the provider portal:

Once you update the Nameservers, it may take sometime for propagation (12-24 hrs.) and once done, we can access our WordPress website by custom domain instead of IP address:

Setting UP SSL

Now, it may be that the package, you purchased from domain provider, comes with SSL certificate along with your domain purchase or it may be a separate item you can purchase from your domain provider.

In my case, SSL certificate was not included and instead of buying it separately, I choose to use free SSL certificate from the Let’s Encrypt certificate authority.

AWS has a nice article, which covers all the details for this step. Following is a short summary of steps you can do to enable HTTPS on your WordPress instance.

  • Connect to your instance (e.g. SSH from Lightsail web console)
  • sudo /opt/bitnami/bncert-tool
  • Enter domain list separated by space (e.g. example.com www.example.com)
  • Enable/disable redirections: (e.g. enter Yes Yes No)

sample screenshots (replace domain names with your custom domain name (e.g. mgarh.pk)

It may ask for some other yes/no type questions (please check the above mentioned article from AWS Lightsail for more details, if needed.) and in few seconds, the process will be done.

With this part completed, we have an HTTPS enabled WordPress website which can be accessed by by visiting a custom domain address in the browser.

Summary

Amazon LightSail is a Virtual Private Server. It is a flat-rate, low-cost computing solution with easy setup and low maintenance. It is a scale-down version of EC2 which is ideal for developers, enthusiasts and small teams.

In this post, we learned how to use a custom domain with WordPress running on Lightsail instance. We saw how Static IP Address, DNS Zones and DNS Records helps us to achieve this common requirement. We also covered how to enable HTTPs for instance running WordPress.

Let me know, if you have some questions or comments. Till next time.

References