Table of content:
- Create dockerized NextJS app - part 1
- Deploy dockerized app to AWS EB - part 2
- Connect custom domain to our application - previous part
Hello everyone.
In previous parts we created dockerized NextJS app, deployed it to AWS EB and connected our app to custom domain.
In this part we are going to set up redirects from http to https (for security reasons) and from www to non-www (for SEO reasons).
Everything in here is within AWS Free tier.
Also please pay attention that all links to AWS I provide use my region of choice, if you're using different AWS region make sure to change it before making any changes!
Setting up redirects
To set up redirects we need to open EC2 Load Balancers Console, select our balancer and open Listeners tab.
We will start with redirecting http to https:
- In
HTTPlistener rowRulescolumn clickView/edit rules - Switch to
Edit rulesmode - open Pen tab - Click on Pen icon on the left of
HTTP 80: default action - Delete default action in
THENcolumn - Click
Add action->Redirect to - Enter port
443on the right of protocol dropdown and click check icon to save changes - Click
Update.
Next we will redirect www to non-www:
- Switch to
Add rulesmode - Click
Insert rule -
IFcolumn selectHost header - Inside
isfield enterwww.yourwebsite -
THENcolumn clickAdd action->Redirect to - Enter port 443 and save changes
We also want to set redirection from www to non-www on https connections:
- Go back to Listeners tab
- Click
View/edit rulesin HTTPS row - Add new rule:
-
IFhost header iswww.yourdomain -
THENredirect to - Set port 443
- Change
Origin host, path, querytoCustom - Replace value of
Hostfield with your website domain
-
- Save changes.
You now have fully functional https website that is being served completely free of charge (within Free tier quota of course).
Hope you liked the series. Bye-bye =)
Top comments (0)