@@ -111,11 +111,132 @@ For development, you can run services directly:
111111
112112### Nginx Proxy (Production Recommended)
113113For production deployment, nginx handles:
114- 1 . ** Wallet Service Proxying** : ` /wallet/* ` → ` localhost:9003 `
115- 2 . ** SSL Termination** : Single certificate for entire application
116- 3 . ** WebSocket Proxying** : Proper upgrade headers for relay WebSocket
117- 4 . ** Static Asset Caching** : Optimal performance for React app
118- 5 . ** Security Headers** : CORS, CSP, and other protections
114+ 1 . ** Relay WebSocket Proxying** : ` /relay ` and ` /relay/ ` → ` localhost:9001 ` (strips prefix)
115+ 2 . ** Wallet Service Proxying** : ` /wallet/* ` → ` localhost:9003 `
116+ 3 . ** SSL Termination** : Single certificate for entire application
117+ 4 . ** WebSocket Proxying** : Proper upgrade headers for relay WebSocket
118+ 5 . ** Static Asset Caching** : Optimal performance for React app
119+ 6 . ** Security Headers** : CORS, CSP, and other protections
120+
121+ #### Complete Working Nginx Configuration
122+ Here's a complete working nginx configuration for the HORNETS Relay Panel (tested on macOS and Linux):
123+
124+ ``` nginx
125+ # Define upstream servers for each service (using explicit IPv4 addresses)
126+ upstream transcribe_api {
127+ server 127.0.0.1:8000;
128+ }
129+
130+ upstream relay_service {
131+ server 127.0.0.1:9001;
132+ }
133+
134+ upstream panel_service {
135+ server 127.0.0.1:9002;
136+ }
137+
138+ upstream wallet_service {
139+ server 127.0.0.1:9003;
140+ }
141+
142+ # WebSocket connection upgrade mapping
143+ map $http_upgrade $connection_upgrade {
144+ default upgrade;
145+ '' close;
146+ }
147+
148+ # Main server block listening on HTTP
149+ server {
150+ listen 80; # Nginx listens on port 80 locally
151+ server_name _; # Accept all hostnames (localhost, ngrok, custom domains, etc.)
152+
153+ # Basic Security Headers
154+ add_header X-Frame-Options "SAMEORIGIN";
155+ add_header X-Content-Type-Options "nosniff";
156+ add_header X-XSS-Protection "1; mode=block";
157+ server_tokens off;
158+
159+ # Increase buffer sizes for large files
160+ client_max_body_size 100M;
161+
162+ # Forward client IP and protocol
163+ proxy_set_header X-Real-IP $remote_addr;
164+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
165+ proxy_set_header X-Forwarded-Proto $scheme;
166+ proxy_set_header Host $host;
167+
168+ # Health check endpoint - exact match first
169+ location = /health {
170+ access_log off;
171+ return 200 "healthy\n";
172+ add_header Content-Type text/plain;
173+ }
174+
175+ # Relay WebSocket service - handle both /relay and /relay/
176+ location ~ ^/relay/?$ {
177+ # Strip the /relay prefix (with or without trailing slash) when forwarding to the service
178+ rewrite ^/relay/?$ / break;
179+
180+ proxy_pass http://relay_service;
181+
182+ # WebSocket-specific headers
183+ proxy_http_version 1.1;
184+ proxy_set_header Upgrade $http_upgrade;
185+ proxy_set_header Connection $connection_upgrade;
186+ proxy_set_header Host $host;
187+ proxy_cache_bypass $http_upgrade;
188+
189+ # Extended timeouts for WebSocket connections
190+ proxy_read_timeout 86400s;
191+ proxy_send_timeout 86400s;
192+ proxy_connect_timeout 60s;
193+
194+ # Additional headers for tunnel compatibility
195+ proxy_set_header X-Forwarded-Proto $scheme;
196+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
197+ proxy_set_header X-Real-IP $remote_addr;
198+ }
199+
200+ # Transcribe service
201+ location /transcribe/ {
202+ rewrite ^/transcribe/(.*)$ /$1 break;
203+ proxy_pass http://transcribe_api;
204+ }
205+
206+ # Wallet service
207+ location /wallet/ {
208+ rewrite ^/wallet/(.*)$ /$1 break;
209+ proxy_pass http://wallet_service;
210+ }
211+
212+ # Default location - Panel service (frontend + API) - MUST BE LAST
213+ location / {
214+ proxy_pass http://panel_service;
215+ proxy_set_header Host $host;
216+ proxy_set_header X-Real-IP $remote_addr;
217+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
218+ proxy_set_header X-Forwarded-Proto $scheme;
219+
220+ # Handle WebSocket if needed
221+ proxy_http_version 1.1;
222+ proxy_set_header Upgrade $http_upgrade;
223+ proxy_set_header Connection $connection_upgrade;
224+ }
225+ }
226+ ```
227+
228+ ** Key Configuration Details:**
229+ - ** Relay WebSocket** : Uses regex matching ` ^/relay/?$ ` to handle both ` /relay ` and ` /relay/ ` paths
230+ - ** Rewrite Rule** : Strips the ` /relay ` prefix before forwarding to the relay service at port 9001
231+ - ** WebSocket Support** : Proper upgrade headers and extended timeouts for WebSocket connections
232+ - ** Service Routing** : Panel (root), wallet (` /wallet/ ` ), transcribe (` /transcribe/ ` ), and relay (` /relay ` )
233+ - ** Security** : Basic security headers and proper client IP forwarding
234+
235+ ** Deployment Steps:**
236+ 1 . Save this configuration to ` /etc/nginx/sites-available/hornets ` (or ` /opt/homebrew/etc/nginx/conf.d/hornets.conf ` on macOS)
237+ 2 . Enable the site: ` sudo ln -s /etc/nginx/sites-available/hornets /etc/nginx/sites-enabled/ `
238+ 3 . Test configuration: ` sudo nginx -t `
239+ 4 . Reload nginx: ` sudo nginx -s reload `
119240
120241## 📋 Prerequisites
121242
0 commit comments