Ever tried setting up multiple web applications under the same domain? Where users can access applications running on the same server with different path names? For instance, you hosted a react app at www.example.com and desire to have a Wordpress blog at www.example.com/blog. This is where the concept of reverse proxy kicks in and helps you accomplish what you are looking for.
What’s a proxy and the difference between the forward & reverse proxy?
A simple definition for “proxy” means that data is passing through a third party, before reaching to the actual location. Forward or regular proxies are servers that encapsulate the original identity of the requestor i.e., users stay anonymous to the host server.
Reverse proxy as the name suggests does the opposite of what a forward proxy can do. It takes requests from the user and forwards them to the host web servers acting as a load balancer. We can leverage this behaviour to serve different apps under the same hood.
To summarise, the forward proxy hides the clients whereas a reverse proxy hides the servers.
Enough of theory, let's get to work!
How to configure a reverse proxy in AWS?
Before we move onto configuration, make sure your web application is deployed to AWS elastic beanstalk. If it’s not, check out this article ( Easy steps to deploy a node application on AWS ).
Step: 1
Go to your EC2 instances from the AWS console.
Step: 2
Scroll to the bottom and click on Load balancers to check if your instances are in an active state.
Step: 3
Create a Target Group for your instance
Step: 4
Name your target group and click ‘ Create ’. Default settings are fine here.
Step: 5
Select the target group you just created and click ‘ Edit ’.
Step: 6
Select a running instance you want to register with your target group (in this case, it's a WordPress blog) and click ‘Add to registered ’.
After it shows up in the Registered targets, click on ‘ Save ’
Step: 7
Now, go back to your load balancers and select the one you want to proxy. Click on Listeners tab and click on “ View/edit rules ” of the HTTPS: 443 listener you configured while setting up SSL.
Step: 8
Tap on the + icon and click “ Insert Rule ”
Step: 9
Add the following 2 rules to proxy the blog server every time a user hits the blog path:
IF Path is /blog THEN Forward to example-blog
IF Path is /blog/* THEN Forward to example-blog
Step: 10
Let’s see this in action!
Give an 👏 if this article was helpful and leave your queries in the comments section below.
Top comments (0)