mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-10-23 07:42:05 +00:00
126 lines
4.1 KiB
Plaintext
126 lines
4.1 KiB
Plaintext
server {
|
|
listen 3000;
|
|
server_name localhost;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
tcp_nopush on;
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/xml
|
|
text/javascript
|
|
application/javascript
|
|
application/xml+rss
|
|
application/json
|
|
application/xml;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options DENY always;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# Handle client-side routing
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# API proxy
|
|
location /api/ {
|
|
proxy_pass http://${BACKEND_HOST}:${BACKEND_PORT};
|
|
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_set_header X-Forwarded-Host $host;
|
|
|
|
# Preserve original client IP through proxy chain
|
|
proxy_set_header X-Original-Forwarded-For $http_x_forwarded_for;
|
|
|
|
# CORS headers for API calls - even though backend is doing it
|
|
add_header Access-Control-Allow-Origin * always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization" always;
|
|
|
|
# Handle preflight requests
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
}
|
|
|
|
# SSE (Server-Sent Events) specific configuration
|
|
location /api/v1/ws/status/ {
|
|
proxy_pass http://${BACKEND_HOST}:${BACKEND_PORT};
|
|
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_set_header X-Forwarded-Host $host;
|
|
|
|
# Critical SSE settings
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
proxy_set_header Connection '';
|
|
proxy_http_version 1.1;
|
|
chunked_transfer_encoding off;
|
|
|
|
# Timeout settings for long-lived connections
|
|
proxy_read_timeout 24h;
|
|
proxy_send_timeout 24h;
|
|
proxy_connect_timeout 60s;
|
|
|
|
# Disable nginx buffering for real-time streaming
|
|
proxy_request_buffering off;
|
|
proxy_max_temp_file_size 0;
|
|
|
|
# CORS headers for SSE - commented out to let backend handle CORS
|
|
# add_header Access-Control-Allow-Origin * always;
|
|
# add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
|
|
# add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization" always;
|
|
|
|
# Handle preflight requests
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
}
|
|
|
|
# WebSocket upgrade handling
|
|
location /api/v1/agents/ws {
|
|
proxy_pass http://${BACKEND_HOST}:${BACKEND_PORT};
|
|
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_set_header X-Forwarded-Host $host;
|
|
|
|
# WebSocket timeout settings
|
|
proxy_read_timeout 24h;
|
|
proxy_send_timeout 24h;
|
|
proxy_connect_timeout 60s;
|
|
|
|
# Disable buffering for WebSocket
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
}
|
|
|
|
# Static assets caching
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# Health check endpoint
|
|
location /health {
|
|
access_log off;
|
|
return 200 "healthy\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|