Nginx Reverse Proxy: Run Multiple Services on One Domain
Lim Bunheng
0:00 / 0:00
Nginx Reverse Proxy: Run Multiple Services on One Domain
63 просмотра · 10 дней назад
Lim Bunheng
6 подписчиков
63 просмотра · 10 дней назад
Nginx Reverse Proxy with Multiple Services | Ubuntu + AWS EC2
In this tutorial, I demonstrate how to configure Nginx as a Reverse Proxy to route multiple services through a single domain.
Instead of accessing each service using different ports, we can access them through different paths:
bunheng.online/ → Frontend
bunheng.online/api/ → API
bunheng.online/admin/ → Admin Dashboard
Step-by-Step Configuration
1. Create folders to store the files
sudo mkdir -p /var/www/proxy/frontend
sudo mkdir -p /var/www/proxy/api
sudo mkdir -p /var/www/proxy/admin
2. Upload files into their own folders
Using FileZilla, upload each index.html file into its corresponding folder.
3. Create the Nginx Reverse Proxy configuration
sudo nano /etc/nginx/sites-available/web.conf
Add the following configuration:
server {
listen 80;
server_name bunheng.online;
Frontend
location / {
proxy_pass http://127.0.0.1:6101;
}
API service
location /api/ {
proxy_pass http://127.0.0.1:6102/;
}
Admin dashboard
location /admin/ {
proxy_pass http://127.0.0.1:6103/;
}
}
4. Enable the Nginx configuration
sudo ln -s /etc/nginx/sites-available/web.conf /etc/nginx/sites-enabled/web.conf
5. Test the Nginx configuration
sudo nginx -t
You should see:
syntax is ok
test is successful
6. Reload Nginx
sudo systemctl reload nginx
7. Start the three services
Frontend - Port 6101
cd /var/www/proxy/frontend
python3 -m http.server 6101
API - Port 6102
cd /var/www/proxy/api
python3 -m http.server 6102
Admin - Port 6103
cd /var/www/proxy/admin
python3 -m http.server 6103
Keep each service running in its own terminal.
Technologies Used
Nginx
Ubuntu Server
AWS EC2
AWS Route 53
Python HTTP Server
FileZilla
HTML/CSS
Reverse Proxy
What You Will Learn
How a Reverse Proxy works
How to configure Nginx
How to route multiple services through one domain
How to use sites-available and sites-enabled
How to test and reload Nginx
How to run multiple services on different ports
Basic AWS EC2 and Route 53 deployment
If you found this tutorial useful, don't forget to Like, Subscribe, and Share for more tutorials about Web Development, Linux, AWS, Networking, and Backend Development.
#Nginx #ReverseProxy #AWS #EC2 #Ubuntu #Route53 #Linux #DevOps #WebDevelopment #NginxTutorial #ServerDeployment #AWSDeployment