[Day 4] 5. Reverse Proxy Setup with Nginx and Apache
In this setup, we'll use Nginx as a reverse proxy in front of an Apache server. The flow looks like this:
Client → Nginx → Apache → Nginx → Client
Machines:
- Nginx (VM1) IP:
192.168.80.128 - Apache (VM2) IP:
192.168.80.130
Steps:
-
Install Nginx on VM1:
bashsudo apt-get install nginx sudo systemctl enable --now nginx -
Check Apache and Nginx installation:
bashsudo which apache2 sudo which nginx -
Configure Nginx:
-
Remove any existing configurations:
bashsudo rm /etc/nginx/sites-enabled/* -
Create a new configuration file:
bashsudo vim /etc/nginx/sites-available/rp.conf -
Add the following configuration to
:rp.confplaintextserver { listen 80; location / { proxy_pass http://192.168.0.130; # Apache server IP } } -
Explanation:
- : Specifies the root URL.
location / - : Redirects incoming requests to the Apache server at
proxy_pass.http://192.168.0.130
-
-
Create a symbolic link for the configuration:
bashsudo ln -s /etc/nginx/sites-available/rp.conf /etc/nginx/sites-enabled/ -
Test the Nginx configuration:
bashsudo nginx -t -c /etc/nginx/nginx.conf- : Tests the configuration.
-t - : Specifies the configuration file.
-c
-
Ensure Apache is running: Make sure the Apache server is running on VM2 (
).192.168.0.130
This setup configures Nginx as a reverse proxy that forwards requests to the Apache server. The Nginx server listens on port 80, and any incoming requests are passed to the Apache server running on VM2.
Read Next
[Day 4] 6. SQUID
For this setup, we need to configure **Squid** as a reverse proxy. Follow the steps below: **Important:** SQUID runs on port **3128** by default....
[Day 4] 7. Extra
1. **Router can have multiple Network Interface Cards (NICs):** - A router can have multiple network interfaces to connect to different net...