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
HTTP
listener rowRules
column clickView/edit rules
- Switch to
Edit rules
mode - open Pen tab - Click on Pen icon on the left of
HTTP 80: default action
- Delete default action in
THEN
column - Click
Add action
->Redirect to
- Enter port
443
on 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 rules
mode - Click
Insert rule
-
IF
column selectHost header
- Inside
is
field enterwww.yourwebsite
-
THEN
column 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 rules
in HTTPS row - Add new rule:
-
IF
host header iswww.yourdomain
-
THEN
redirect to - Set port 443
- Change
Origin host, path, query
toCustom
- Replace value of
Host
field 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)