Files
2025-10-01 23:37:51 +08:00

123 lines
4.0 KiB
Nginx Configuration File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

server {
listen ${NGINX_PORT} default_server;
listen [::]:${NGINX_PORT} default_server;
server_name _;
# 前端资源
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# 后端API代理backend使用host网络暴露10082端口
location /prod-api/ {
proxy_pass http://127.0.0.1:10082/;
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/ {
proxy_pass http://127.0.0.1:10082/websocket/;
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;
}
# Python推理服务代理映射到宿主机端口
location /python-api/ {
proxy_pass http://127.0.0.1:8000/;
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;
}
# 视频流代理HTTP-FLVbackend使用host网络暴露10083端口
location /live {
proxy_pass http://127.0.0.1:10083/live;
proxy_http_version 1.1;
# 【关键】禁用所有缓冲,立即转发每一个字节
proxy_buffering off;
proxy_cache off;
proxy_request_buffering off;
proxy_max_temp_file_size 0;
# 设置超时时间(视频流长连接)
proxy_connect_timeout 120s;
proxy_send_timeout 7200s;
proxy_read_timeout 7200s;
# 请求头
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 Connection "";
# 【关键】响应头 - 禁用缓冲和缓存
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支持
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
add_header Access-Control-Allow-Headers '*' always;
# 【关键】TCP 优化
tcp_nopush off;
tcp_nodelay on;
keepalive_timeout 0;
}
# 视频流代理HLS
location /hls {
proxy_pass http://127.0.0.1:10083;
proxy_http_version 1.1;
# HLS也需要禁用缓冲
proxy_buffering off;
proxy_cache off;
proxy_request_buffering off;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# CORS支持
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers '*';
}
# 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;
}