Configure Subdomain to Amazon EC2 with Amazon Route 53 + NGINX + Docker
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.
Choose the domain that you want to configure.
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.
After successfully created the record, try to open the subdomain through browser. We will get the response like the our domain did.
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
You can see the response from the curl test below. Ideally, when we accessing our subdomain, it should be have the same output from
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
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
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!