Configure Subdomain to Amazon EC2 with Amazon Route 53 + NGINX + Docker

Photo by pixabay.com

Hi everyone! With me again and again to share some experience, though or opinion about technology related with software engineering field. On previous story, we already learn about configuring domain to Amazon EC2 with Amazon Route 53. The details of the story can be found here: https://medium.com/@bismobaruno/4832900e353b

Now, we will learn how the configure subdomain on our app. Maybe you will have multiple service on your instance and want to separate by subdomain.

Assume you already have domain that successfully running on your instance. If you don’t have any, you can read my previous story and try to build it. Because in this story, we will continue the previous work for achieving our goal.

Go to Route 53 service, choose Hosted zones menu.

Picture 1 Route 53 Page

Choose the domain that you want to configure.

Picture 2 Hosted Zones Page

Click Create Record Set button, fill the information on the form. Like the subdomain name, Alias should be no, and Value is Public IP of the instance.

Picture 3 Create Record Set

After successfully created the record, try to open the subdomain through browser. We will get the response like the our domain did.

Picture 4 Accessing Subdomain

Next, we will make it works. Let’s configure NGINX proxy to serve the subdomain and pointing to our Go App endpoint. The endpoint we will use is /health_check

You can see the response from the curl test below. Ideally, when we accessing our subdomain, it should be have the same output from /health_check endpoint.

Picture 5 Check Go App Endpoint

Modify NGINX config like script below. We should adding server name for specify the route will be pointing to which service.

Next, we will update NGINX config and reset the service. Find the container id from our NGINX service with this command

docker ps
Picture 6 Check NGINX Container ID

Copy the modified file to container

docker cp nginx.conf 3cd026147dcc:/etc/nginx/conf.d/default.conf

Reload NGINX service

docker exec -it 3cd026147dcc nginx -s reload
Picture 7 Successfully Reload NGINX service
Picture 8 Successfully Setup Subdomain

And Voila, it’s works! Now you can access the subdomain that successfully pointing to /health_check endpoint !

Hope you enjoy it, I’m happy if this article useful for you! Happy Pointing!

Thank you!

Others story that still related

Software Engineer | Traveler | Guitarist | J-Lovers