Reverse Proxy Lab
This exercise installs NGINX on LINUXBOX. The proxy listens only inside the isolated NETLAB network, and its backend listens only on LINUXBOX’s loopback address.
The exercise requires the optional NETLAB environment.
Build the Backend and Proxy
Section titled “Build the Backend and Proxy”-
On LINUXBOX, install NGINX and create a small backend page:
sudo -iapt updateapt install nginxmkdir /var/www/netguide-backendecho "Response from the backend service" > /var/www/netguide-backend/index.htmlThe
sudo -icommand opens an administrative shell. Leave this terminal open for the rest of the exercise. The finalexitcommand closes the administrative shell. -
Open a new configuration file:
nano /etc/nginx/sites-available/netguide -
Enter this configuration, then save and close the file:
server {listen 127.0.0.1:8000;server_name _;root /var/www/netguide-backend;}server {listen 8080;server_name _;location / {proxy_pass http://127.0.0.1:8000;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}} -
Enable the configuration and reload NGINX:
ln -s /etc/nginx/sites-available/netguide /etc/nginx/sites-enabled/netguidenginx -tsystemctl reload nginxip -4 addr -
On WINCLIENT, replace
<LINUXBOX-IP>with LINUXBOX’s NETLAB Internet Protocol (IP) address:curl.exe http://<LINUXBOX-IP>:8080The response should say:
Response from the backend service
WINCLIENT connects to NGINX on Transmission Control Protocol (TCP) port 8080. NGINX terminates that connection and creates a separate connection to the backend on loopback TCP port 8000.
Verify the Two Listeners
Section titled “Verify the Two Listeners”On LINUXBOX:
ss -lntFind:
0.0.0.0:8080, which accepts connections through LINUXBOX’s NETLAB interface127.0.0.1:8000, which accepts connections only from LINUXBOX itself
This difference is why WINCLIENT can contact the proxy but cannot connect directly to the backend.
Remove the Lab Configuration
Section titled “Remove the Lab Configuration”Run these commands from the administrative shell opened earlier:
rm /etc/nginx/sites-enabled/netguiderm /etc/nginx/sites-available/netguiderm /var/www/netguide-backend/index.htmlrmdir /var/www/netguide-backendsystemctl reload nginxsystemctl disable --now nginxexitThese commands leave the NGINX package installed but stop and disable its service.
Confirm that the listener has been removed:
ss -lntTCP ports 8000 and 8080 should no longer appear.
Further Learning
Section titled “Further Learning”- NGINX proxy module documentation documents the settings used by the lab.
- NGINX beginner’s guide explains configuration files and service control.