2025-09-30 14:23:33 +08:00
|
|
|
|
server {
|
2025-09-30 20:56:55 +08:00
|
|
|
|
listen ${NGINX_PORT} default_server;
|
|
|
|
|
|
listen [::]:${NGINX_PORT} default_server;
|
|
|
|
|
|
server_name _;
|
2025-09-30 14:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
# 前端资源
|
|
|
|
|
|
location / {
|
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
|
index index.html index.htm;
|
|
|
|
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-01 17:48:57 +08:00
|
|
|
|
# 后端API代理(backend使用host网络,暴露10082端口)
|
2025-09-30 14:23:33 +08:00
|
|
|
|
location /prod-api/ {
|
2025-10-01 17:48:57 +08:00
|
|
|
|
proxy_pass http://127.0.0.1:10082/;
|
2025-09-30 14:23:33 +08:00
|
|
|
|
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_connect_timeout 600;
|
|
|
|
|
|
proxy_read_timeout 600;
|
|
|
|
|
|
proxy_send_timeout 600;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# WebSocket支持(用于视频流)
|
|
|
|
|
|
location /websocket/ {
|
2025-10-01 17:48:57 +08:00
|
|
|
|
proxy_pass http://127.0.0.1:10082/websocket/;
|
2025-09-30 14:23:33 +08:00
|
|
|
|
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_connect_timeout 7d;
|
|
|
|
|
|
proxy_send_timeout 7d;
|
|
|
|
|
|
proxy_read_timeout 7d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-30 20:48:14 +08:00
|
|
|
|
# Python推理服务代理(映射到宿主机端口)
|
2025-09-30 14:23:33 +08:00
|
|
|
|
location /python-api/ {
|
2025-09-30 20:48:14 +08:00
|
|
|
|
proxy_pass http://127.0.0.1:8000/;
|
2025-09-30 14:23:33 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-01 17:48:57 +08:00
|
|
|
|
# 视频流代理(HTTP-FLV,backend使用host网络,暴露10083端口)
|
2025-09-30 20:27:56 +08:00
|
|
|
|
location /live {
|
2025-10-01 21:25:24 +08:00
|
|
|
|
proxy_pass http://127.0.0.1:10083/live;
|
2025-09-30 20:27:56 +08:00
|
|
|
|
proxy_http_version 1.1;
|
2025-09-30 21:12:52 +08:00
|
|
|
|
|
2025-10-01 23:32:29 +08:00
|
|
|
|
# 【关键】禁用所有缓冲,立即转发每一个字节
|
2025-09-30 21:12:52 +08:00
|
|
|
|
proxy_buffering off;
|
|
|
|
|
|
proxy_cache off;
|
|
|
|
|
|
proxy_request_buffering off;
|
2025-10-01 23:27:08 +08:00
|
|
|
|
proxy_max_temp_file_size 0;
|
2025-09-30 21:12:52 +08:00
|
|
|
|
|
2025-10-01 23:32:29 +08:00
|
|
|
|
# 设置超时时间(视频流长连接)
|
2025-10-01 21:31:30 +08:00
|
|
|
|
proxy_connect_timeout 120s;
|
|
|
|
|
|
proxy_send_timeout 7200s;
|
|
|
|
|
|
proxy_read_timeout 7200s;
|
2025-09-30 21:12:52 +08:00
|
|
|
|
|
2025-10-01 23:32:29 +08:00
|
|
|
|
# 请求头
|
2025-09-30 20:27:56 +08:00
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2025-10-01 23:32:29 +08:00
|
|
|
|
proxy_set_header Connection "";
|
2025-09-30 21:12:52 +08:00
|
|
|
|
|
2025-10-01 23:32:29 +08:00
|
|
|
|
# 【关键】响应头 - 禁用缓冲和缓存
|
|
|
|
|
|
add_header X-Accel-Buffering no always;
|
|
|
|
|
|
add_header Cache-Control 'no-cache, no-store, must-revalidate' always;
|
|
|
|
|
|
add_header Pragma no-cache always;
|
|
|
|
|
|
add_header Expires 0 always;
|
|
|
|
|
|
|
|
|
|
|
|
# CORS支持
|
2025-10-01 23:27:08 +08:00
|
|
|
|
add_header Access-Control-Allow-Origin * always;
|
|
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
|
|
|
|
|
|
add_header Access-Control-Allow-Headers '*' always;
|
2025-10-01 21:31:30 +08:00
|
|
|
|
|
2025-10-01 23:32:29 +08:00
|
|
|
|
# 【关键】TCP 优化
|
2025-10-01 23:27:08 +08:00
|
|
|
|
tcp_nopush off;
|
|
|
|
|
|
tcp_nodelay on;
|
2025-10-01 23:32:29 +08:00
|
|
|
|
keepalive_timeout 0;
|
2025-09-30 20:27:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 视频流代理(HLS)
|
|
|
|
|
|
location /hls {
|
2025-10-01 17:48:57 +08:00
|
|
|
|
proxy_pass http://127.0.0.1:10083;
|
2025-09-30 20:27:56 +08:00
|
|
|
|
proxy_http_version 1.1;
|
2025-09-30 21:12:52 +08:00
|
|
|
|
|
|
|
|
|
|
# HLS也需要禁用缓冲
|
|
|
|
|
|
proxy_buffering off;
|
|
|
|
|
|
proxy_cache off;
|
|
|
|
|
|
proxy_request_buffering off;
|
|
|
|
|
|
|
|
|
|
|
|
# 超时设置
|
|
|
|
|
|
proxy_connect_timeout 60s;
|
|
|
|
|
|
proxy_send_timeout 3600s;
|
|
|
|
|
|
proxy_read_timeout 3600s;
|
|
|
|
|
|
|
2025-09-30 20:27:56 +08:00
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2025-09-30 21:12:52 +08:00
|
|
|
|
|
|
|
|
|
|
# CORS支持
|
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
|
|
|
|
|
add_header Access-Control-Allow-Headers '*';
|
2025-09-30 20:27:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-30 14:23:33 +08:00
|
|
|
|
# MinIO使用外部服务,不需要代理
|
|
|
|
|
|
|
|
|
|
|
|
# 错误页面配置
|
|
|
|
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
|
|
location = /50x.html {
|
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 日志配置
|
|
|
|
|
|
access_log /var/log/nginx/access.log;
|
|
|
|
|
|
error_log /var/log/nginx/error.log;
|
|
|
|
|
|
}
|