refactor(nginx): nginx only handles rtmp connections

Not longer handles frontend & backend. Partially for ease of development and also for separation of concenrs.
This commit is contained in:
2026-05-14 20:20:37 +01:00
parent 265a96acc1
commit 2e6679cb89
4 changed files with 26 additions and 57 deletions

View File

@@ -21,6 +21,8 @@ services:
- .env - .env
environment: environment:
FRONTEND_URL: http://localhost FRONTEND_URL: http://localhost
ports:
- "8080:8080"
restart: unless-stopped restart: unless-stopped
frontend: frontend:
@@ -35,18 +37,19 @@ services:
VITE_GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID} VITE_GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
depends_on: depends_on:
- backend - backend
ports:
- "1935:1935"
restart: unless-stopped restart: unless-stopped
nginx: rtmp:
build: build:
context: ./nginx context: ./nginx
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: vod_nginx container_name: vod_rtmp
depends_on: depends_on:
- backend - backend
- frontend - frontend
ports: ports:
- "80:80"
- "1935:1935" - "1935:1935"
volumes: volumes:
- ${STREAM_DATA}:/stream - ${STREAM_DATA}:/stream

View File

@@ -3,4 +3,3 @@ FROM tiangolo/nginx-rtmp
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 1935 EXPOSE 1935
EXPOSE 8080

View File

@@ -3,6 +3,15 @@ events {
worker_connections 1024; worker_connections 1024;
} }
upstream backend {
server 127.0.0.1:8080;
}
upstream frontend {
server 127.0.0.1:5173;
}
rtmp { rtmp {
server { server {
listen 1935; listen 1935;
@@ -23,61 +32,19 @@ rtmp {
} }
} }
# Serve the HLS segments over HTTP
http { http {
sendfile off;
tcp_nopush on;
default_type application/octet-stream;
# Allow large uploads (matches Spring Boot multipart limit)
client_max_body_size 2g;
server { server {
listen 80; listen 8088;
# Spring Boot API
location /api/v1/ {
proxy_pass http://vod_backend:8080;
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;
# Large upload timeouts
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_request_buffering off;
}
# HLS stream playback
location /hls { location /hls {
types { types {
application/vnd.apple.mpegurl m3u8; application/vnd.apple.mpegurl m3u8; # proper MIME for HLS playlists
video/mp2t ts; video/mp2t ts; # MPEG-TS segment MIME
} }
root /tmp; root /tmp;
add_header Cache-Control no-cache; add_header Cache-Control no-cache; # prevent stale segments
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Origin *; # CORS for browser playback
}
# RTMP stats
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/html;
}
# Frontend (Vite dev server) — catch-all
location / {
proxy_pass http://vod_frontend:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
} }
} }
} }

View File

@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS streams;
DROP TABLE IF EXISTS clips; DROP TABLE IF EXISTS clips;
DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS users;
@@ -10,7 +11,7 @@ CREATE TABLE IF NOT EXISTS users (
profile_picture_url VARCHAR(255), profile_picture_url VARCHAR(255),
role INTEGER DEFAULT 0, role INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
stream_key VARCHAR(64) NOT NULL stream_key VARCHAR(64)
); );
CREATE TABLE IF NOT EXISTS streams ( CREATE TABLE IF NOT EXISTS streams (
@@ -18,11 +19,10 @@ CREATE TABLE IF NOT EXISTS streams (
user_id BIGSERIAL, user_id BIGSERIAL,
start_time TIMESTAMPTZ DEFAULT NOW(), start_time TIMESTAMPTZ DEFAULT NOW(),
end_time TIMESTAMPTZ DEFAULT NULL, end_time TIMESTAMPTZ DEFAULT NULL,
last_seen TIMESTAMPTZ DEFAULT NULL last_seen TIMESTAMPTZ DEFAULT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) );
CREATE TABLE IF NOT EXISTS clips ( CREATE TABLE IF NOT EXISTS clips (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,