Перейти к содержимому

FT4 Rout to multi path nginx

NEN SEANGHAI

0:00 / 0:00

FT4 Rout to multi path nginx

9 просмотров · 7 дней назад
NEN SEANGHAI
7 подписчиков
9 просмотров · 7 дней назад
NGINX Reverse Proxy – Route Multiple Services with Different Paths In this tutorial, we’ll learn how to configure NGINX as a Reverse Proxy to route traffic to multiple backend services using different URL paths. Instead of exposing multiple ports directly, we can use a single domain and let NGINX handle the routing: 🌐 `Seanghai.online/` → Frontend 🔌 `Seanghai.online/api/` → API Service 🛠️ `Seanghai.online/admin/` → Admin Dashboard 📌 What You'll Learn ✅ Create folders for multiple web services ✅ Configure NGINX Reverse Proxy ✅ Route traffic using different paths ✅ Configure `proxy_pass` ✅ Enable an NGINX site configuration ✅ Test NGINX configuration ✅ Reload NGINX without stopping the server ✅ Run multiple Python HTTP servers on different ports --- 1️⃣ Create folders to store files ```bash sudo mkdir -p /var/www/proxy/frontend sudo mkdir -p /var/www/proxy/api sudo mkdir -p /var/www/proxy/admin ``` Then place each `index.html` file inside its own folder. ```text /var/www/proxy/ │ ├── frontend/ │ └── index.html │ ├── api/ │ └── index.html │ └── admin/ └── index.html ``` --- 2️⃣ Create NGINX configuration ```bash sudo nano /etc/nginx/sites-available/web.conf ``` Add the following configuration: ```nginx server { listen 80; server_name Seanghai.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/; } } ``` 🔀 Routing Structure ```text ┌── / ────────→ Frontend :6101 │ User → Seanghai.online → NGINX │ ├── /api/ ────→ API :6102 │ └── /admin/ ──→ Admin :6103 ``` --- 3️⃣ Enable the NGINX configuration ```bash sudo ln -s /etc/nginx/sites-available/web.conf /etc/nginx/sites-enabled/web.conf ``` --- 4️⃣ Test NGINX configuration Always test the configuration before reloading: ```bash sudo nginx -t ``` If everything is correct, you should see: ```text syntax is ok test is successful ``` --- 5️⃣ Reload NGINX ```bash sudo systemctl reload nginx ``` --- 6️⃣ Start the Frontend service ```bash cd /var/www/proxy/frontend python3 -m http.server 6101 ``` --- 7️⃣ Start the API service Open another terminal: ```bash cd /var/www/proxy/api python3 -m http.server 6102 ``` --- 8️⃣ Start the Admin service Open another terminal: ```bash cd /var/www/proxy/admin python3 -m http.server 6103 ``` --- 🌍 Final Result After everything is running: ```text http://Seanghai.online/ ↓ Frontend :6101 http://Seanghai.online/api/ ↓ API :6102 http://Seanghai.online/admin/ ↓ Admin :6103 ``` This setup allows *NGINX to act as a single entry point* for multiple applications and services. ⚠️ Important Note The Python `http.server` command is useful for **testing and learning**, but it is generally not recommended as a production web server. For production applications, consider using a proper application server/service manager and configure security, HTTPS, logging, and process management. --- 👍 If this tutorial helps you, don't forget to **Like 👍, Subscribe 🔔, and Share 💬 Comment below if you have any questions about **NGINX Reverse Proxy, Multi-Path Routing, or Linux Server Configuration**. #NGINX #ReverseProxy #NginxTutorial #Linux #DevOps #WebServer