Radek Davidek 22d0e0dfd0 added cors
2026-03-10 15:47:10 +01:00

96 lines
2.9 KiB
Nginx Configuration File

upstream xtream_backend {
server localhost:8080;
}
server {
listen 80;
server_name _;
# Limit request sizes to prevent abuse
client_max_body_size 256M;
# Root location - serve static files and proxy to backend
location / {
# Try to serve static files first, then proxy to backend
proxy_pass http://xtream_backend;
proxy_http_version 1.1;
# Preserve original request information
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;
# WebSocket support (if needed)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Timeouts for long-running requests (streaming)
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 3600s;
# Buffering for streaming
proxy_buffering off;
proxy_request_buffering off;
}
# API endpoints with special handling
location /api/ {
proxy_pass http://xtream_backend;
proxy_http_version 1.1;
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 $server_name;
# For preflight requests
proxy_set_header Access-Control-Allow-Origin *;
# Timeouts for streaming endpoints
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 3600s;
# Disable buffering for stream proxying
proxy_buffering off;
proxy_request_buffering off;
}
# Stream proxy endpoint - special handling for media streams
location /api/stream-proxy {
proxy_pass http://xtream_backend;
proxy_http_version 1.1;
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;
# Important: disable buffering for media streaming
proxy_buffering off;
proxy_request_buffering off;
# Allow range requests for seeking
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
# Long timeout for streaming
proxy_connect_timeout 60s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
# Pass through the 206 Partial Content status
proxy_pass_request_headers on;
}
# Health check endpoint
location /health {
access_log off;
return 200 "OK";
add_header Content-Type "text/plain";
}
}