Spaces:
Running
Running
File size: 4,248 Bytes
73905db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | # π Local Network Deployment Guide: RAG Monolith with Nginx & Docker
This guide explains how to deploy your RAG Monolith application locally using Nginx as a reverse proxy, making it accessible to anyone in your local Wi-Fi or LAN network.
No SSL certificates or DNS are required. This setup automatically supports WebSockets (for pipeline traces) and handles routing dynamically, meaning **it will work even if your server's local IP address changes!**
---
## π οΈ The Architecture
When multiple devices in a local network try to access your application, hardcoding `localhost:8001` or a specific IP in the frontend build will cause connection issues.
We solve this using **Nginx as a unified gateway** on port `8080` (or `80`):
```mermaid
graph TD
Client[Devices on Local Network] -->|Access http://192.168.1.5:8080| Nginx[Nginx Reverse Proxy]
Nginx -->|Route / (Static Files)| Frontend[Frontend Container]
Nginx -->|Route /api, /auth, etc.| Backend[Backend Container]
Nginx -->|Route /ws (WebSockets)| Backend[Backend Container]
```
---
## π Step-by-Step Setup
### Step 1: Create Nginx Configuration
Create a new directory named `nginx` in `/Content/AI-PROJECTS/RAG_FULL_APPLICATION_LOCAL` and write the reverse proxy configuration:
```nginx
# nginx/nginx.conf
server {
listen 80;
# 1. Route for Frontend Static Assets
location / {
proxy_pass http://frontend:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 2. Route for API Endpoints
location ~ ^/(auth|ingest|query|health) {
proxy_pass http://backend:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 3. Route for WebSockets (Pipeline Live Tracer)
location ~ ^/ws/ {
proxy_pass http://backend:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 86400;
}
}
```
---
### Step 2: Update `docker-compose.yml`
Configure your services to use Nginx on the host's port `8080` (or `80`) and leave `VITE_API_BASE_URL` empty so the frontend dynamically uses the active IP:
```yaml
version: "3.9"
services:
backend:
build:
context: ./RAG_FULL_APPLICATION_BACKEND
dockerfile: Dockerfile
ports:
- "8000:8000"
env_file:
- ./RAG_FULL_APPLICATION_BACKEND/.env
volumes:
- ./RAG_FULL_APPLICATION_BACKEND:/app
- ./RAG_FULL_APPLICATION_BACKEND/data:/app/data
depends_on:
- redis
restart: unless-stopped
frontend:
build:
context: ./RAG_FULL_APPLICATION_FRONTEND
dockerfile: Dockerfile
args:
- VITE_API_BASE_URL= # Left empty so it uses window.location.origin dynamically!
depends_on:
- backend
redis:
image: redis:7-alpine
ports:
- "6379:6379"
restart: unless-stopped
nginx:
image: nginx:stable-alpine
ports:
- "8080:80" # Exposes the portal to your local network on port 8080
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- frontend
- backend
restart: unless-stopped
```
---
### Step 3: Run the Application
Start the containers in detached mode:
```bash
docker compose up -d --build
```
---
## π₯ How Others Can Access It
1. **Find your local IP Address:**
Run the following command to find your machine's IP inside your Wi-Fi/LAN network:
```bash
ip route get 1.1.1.1 | awk '{print $7}'
```
*(For example: `192.168.1.5`)*
2. **Access URL:**
Any device connected to the **same Wi-Fi or router** can simply open their browser and visit:
```text
http://<YOUR_LOCAL_IP>:8080
# Example: http://192.168.1.5:8080
```
|