754 lines
27 KiB
Plaintext
754 lines
27 KiB
Plaintext
# /etc/nginx/sites-available/valuefrontier
|
|
# CDN 就绪版本 - 修复 api.valuefrontier.cn 配置
|
|
#
|
|
# 变更说明:
|
|
# 1. 修复 api.valuefrontier.cn 指向正确的后端
|
|
# 2. 添加所有必要的代理规则到 api 域名
|
|
# 3. 添加 CORS 支持(允许 CDN 域名访问)
|
|
|
|
# WebSocket 连接升级映射
|
|
map $http_upgrade $connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|
|
|
|
# ============================================
|
|
# Flask 后端负载均衡(支持多进程)
|
|
# ============================================
|
|
upstream flask_backend {
|
|
server 110.42.32.207:5001;
|
|
keepalive 32;
|
|
}
|
|
|
|
# ============================================
|
|
# HTTP (端口 80) - 主域名
|
|
# ============================================
|
|
server {
|
|
listen 80;
|
|
server_name valuefrontier.cn www.valuefrontier.cn;
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/html;
|
|
}
|
|
|
|
location ~ \.txt$ {
|
|
root /var/www/valuefrontier.cn;
|
|
add_header Content-Type "text/plain";
|
|
}
|
|
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# ============================================
|
|
# HTTPS (端口 443) - 主域名
|
|
# ============================================
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name valuefrontier.cn www.valuefrontier.cn;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/valuefrontier.cn/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/valuefrontier.cn/privkey.pem;
|
|
|
|
# ============================================
|
|
# SEO 文件
|
|
# ============================================
|
|
location = /robots.txt {
|
|
root /var/www/valuefrontier;
|
|
add_header Content-Type "text/plain; charset=utf-8";
|
|
add_header Cache-Control "public, max-age=3600";
|
|
access_log off;
|
|
}
|
|
|
|
location = /sitemap.xml {
|
|
root /var/www/valuefrontier;
|
|
add_header Content-Type "application/xml; charset=utf-8";
|
|
add_header Cache-Control "public, max-age=3600";
|
|
access_log off;
|
|
}
|
|
|
|
# ============================================
|
|
# React 应用静态资源
|
|
# ============================================
|
|
location /static/ {
|
|
alias /var/www/valuefrontier.cn/static/;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
add_header Access-Control-Allow-Origin *;
|
|
}
|
|
|
|
location ~ \.txt$ {
|
|
root /var/www/valuefrontier.cn;
|
|
add_header Content-Type "text/plain";
|
|
}
|
|
|
|
location /manifest.json {
|
|
alias /var/www/valuefrontier.cn/manifest.json;
|
|
add_header Content-Type "application/json";
|
|
}
|
|
|
|
location /favicon.ico {
|
|
alias /var/www/valuefrontier.cn/favicon.ico;
|
|
}
|
|
|
|
# ============================================
|
|
# API 代理(保持现有配置)
|
|
# ============================================
|
|
location /api/ {
|
|
proxy_pass http://flask_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 Connection "";
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
proxy_next_upstream error timeout http_502 http_503 http_504;
|
|
proxy_next_upstream_tries 3;
|
|
}
|
|
|
|
# WebSocket (Socket.IO)
|
|
location /socket.io/ {
|
|
proxy_pass http://flask_backend;
|
|
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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# 实时行情 WebSocket
|
|
location /ws/sse {
|
|
proxy_pass http://127.0.0.1:8765;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
location /ws/szse {
|
|
proxy_pass http://222.128.1.157:8765;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# MCP 服务
|
|
location /mcp/ {
|
|
proxy_pass http://127.0.0.1:8900/;
|
|
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 Connection '';
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
chunked_transfer_encoding on;
|
|
proxy_connect_timeout 75s;
|
|
proxy_send_timeout 300s;
|
|
proxy_read_timeout 300s;
|
|
gzip off;
|
|
add_header X-Accel-Buffering no;
|
|
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
|
|
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
}
|
|
|
|
# 概念板块API
|
|
location /concept-api/ {
|
|
proxy_pass http://222.128.1.157:16801/;
|
|
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;
|
|
add_header Access-Control-Allow-Origin * always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range" always;
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
|
|
# Elasticsearch API
|
|
location /es-api/ {
|
|
proxy_pass http://222.128.1.157:19200/;
|
|
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;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS, HEAD' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# Bytedesk 客服系统
|
|
location /bytedesk/ {
|
|
proxy_pass http://43.143.189.195/;
|
|
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;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
}
|
|
|
|
location /websocket {
|
|
proxy_pass http://43.143.189.195/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_set_header X-Forwarded-Proto $scheme;
|
|
proxy_connect_timeout 86400s;
|
|
proxy_send_timeout 86400s;
|
|
proxy_read_timeout 86400s;
|
|
}
|
|
|
|
location /chat/ {
|
|
proxy_pass http://43.143.189.195/chat/;
|
|
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;
|
|
sub_filter 'http://43.143.189.195' 'https://valuefrontier.cn';
|
|
sub_filter_once off;
|
|
sub_filter_types text/css text/javascript application/javascript application/json;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
}
|
|
|
|
location /config/ {
|
|
proxy_pass http://43.143.189.195/config/;
|
|
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;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
}
|
|
|
|
location ^~ /uploads/ {
|
|
proxy_pass http://43.143.189.195/uploads/;
|
|
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_cache_valid 200 1d;
|
|
expires 1d;
|
|
add_header Cache-Control "public, max-age=86400";
|
|
}
|
|
|
|
location ^~ /file/2025/ {
|
|
proxy_pass http://43.143.189.195/file/2025/;
|
|
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_cache_valid 200 1d;
|
|
expires 1d;
|
|
add_header Cache-Control "public, max-age=86400";
|
|
add_header Access-Control-Allow-Origin *;
|
|
}
|
|
|
|
location /visitor/ {
|
|
proxy_pass http://43.143.189.195/visitor/;
|
|
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 Accept-Encoding "";
|
|
sub_filter 'http://43.143.189.195' 'https://valuefrontier.cn';
|
|
sub_filter_once off;
|
|
sub_filter_types application/json;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
|
|
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
}
|
|
|
|
location = /stomp {
|
|
proxy_pass http://43.143.189.195/api/websocket;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
location /stomp/ {
|
|
proxy_pass http://43.143.189.195/api/websocket/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
location ^~ /avatars/ {
|
|
proxy_pass http://43.143.189.195/uploads/;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_cache_valid 200 1d;
|
|
proxy_cache_bypass $http_cache_control;
|
|
}
|
|
|
|
location /assets/ {
|
|
proxy_pass http://43.143.189.195/assets/;
|
|
proxy_set_header Host $host;
|
|
expires 1d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# 新闻搜索API
|
|
location /news-api/ {
|
|
proxy_pass http://222.128.1.157:21891/;
|
|
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;
|
|
add_header Access-Control-Allow-Origin * always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range" always;
|
|
proxy_connect_timeout 90s;
|
|
proxy_send_timeout 90s;
|
|
proxy_read_timeout 90s;
|
|
}
|
|
|
|
# 研报搜索API
|
|
location /report-api/ {
|
|
proxy_pass http://222.128.1.157:8811/;
|
|
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;
|
|
add_header Access-Control-Allow-Origin * always;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
|
|
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range" always;
|
|
proxy_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
}
|
|
|
|
# 商品分类树数据API
|
|
location /category-api/ {
|
|
proxy_pass http://222.128.1.157:18827/;
|
|
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;
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
proxy_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
proxy_buffering on;
|
|
proxy_buffer_size 128k;
|
|
proxy_buffers 8 256k;
|
|
proxy_busy_buffers_size 512k;
|
|
}
|
|
|
|
# ============================================
|
|
# 官网静态资源
|
|
# ============================================
|
|
location ^~ /css/ {
|
|
root /var/www/valuefrontier;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location ^~ /js/ {
|
|
root /var/www/valuefrontier;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location ^~ /img/ {
|
|
root /var/www/valuefrontier;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location ^~ /videos/ {
|
|
root /var/www/valuefrontier;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location ^~ /fonts/ {
|
|
root /var/www/valuefrontier;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# 官网HTML页面
|
|
location ~ ^/(conversational-ai|customizable-workflows|integration|docs|sign-in|sign-up|reset-password)\.html$ {
|
|
root /var/www/valuefrontier;
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# 官网首页
|
|
location = / {
|
|
root /var/www/valuefrontier;
|
|
try_files /index.html =404;
|
|
}
|
|
|
|
# ============================================
|
|
# React 应用 (默认 catch-all)
|
|
# ============================================
|
|
location / {
|
|
root /var/www/valuefrontier.cn;
|
|
index index.html index.htm;
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
add_header Access-Control-Allow-Origin *;
|
|
}
|
|
}
|
|
}
|
|
|
|
# ============================================
|
|
# api.valuefrontier.cn - API 专用域名
|
|
# ============================================
|
|
|
|
server {
|
|
listen 80;
|
|
server_name api.valuefrontier.cn;
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/html;
|
|
}
|
|
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name api.valuefrontier.cn;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/api.valuefrontier.cn/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/api.valuefrontier.cn/privkey.pem;
|
|
|
|
# SSL 优化
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 1d;
|
|
|
|
# ============================================
|
|
# CORS 配置(允许 CDN 域名访问)
|
|
# ============================================
|
|
|
|
# 允许的来源
|
|
set $cors_origin '';
|
|
if ($http_origin ~* "^https://(www\.)?valuefrontier\.cn$") {
|
|
set $cors_origin $http_origin;
|
|
}
|
|
|
|
# 通用 CORS 头
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization, X-Requested-With' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
|
|
# ============================================
|
|
# Flask API 代理
|
|
# ============================================
|
|
location /api/ {
|
|
# 处理 OPTIONS 预检请求
|
|
if ($request_method = 'OPTIONS') {
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization, X-Requested-With' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
add_header 'Access-Control-Max-Age' 86400;
|
|
add_header 'Content-Type' 'text/plain charset=UTF-8';
|
|
add_header 'Content-Length' 0;
|
|
return 204;
|
|
}
|
|
|
|
proxy_pass http://flask_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 Connection "";
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
proxy_next_upstream error timeout http_502 http_503 http_504;
|
|
proxy_next_upstream_tries 3;
|
|
}
|
|
|
|
# ============================================
|
|
# WebSocket 代理
|
|
# ============================================
|
|
location /socket.io/ {
|
|
proxy_pass http://flask_backend;
|
|
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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# 实时行情 WebSocket - 上交所
|
|
location /ws/sse {
|
|
proxy_pass http://127.0.0.1:8765;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# 实时行情 WebSocket - 深交所
|
|
location /ws/szse {
|
|
proxy_pass http://222.128.1.157:8765;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# ============================================
|
|
# 其他 API 代理
|
|
# ============================================
|
|
|
|
# 概念板块API
|
|
location /concept-api/ {
|
|
proxy_pass http://222.128.1.157:16801/;
|
|
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_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
|
|
# Elasticsearch API
|
|
location /es-api/ {
|
|
proxy_pass http://222.128.1.157:19200/;
|
|
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_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# 新闻搜索API
|
|
location /news-api/ {
|
|
proxy_pass http://222.128.1.157:21891/;
|
|
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_connect_timeout 90s;
|
|
proxy_send_timeout 90s;
|
|
proxy_read_timeout 90s;
|
|
}
|
|
|
|
# 研报搜索API
|
|
location /report-api/ {
|
|
proxy_pass http://222.128.1.157:8811/;
|
|
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_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
}
|
|
|
|
# 商品分类API
|
|
location /category-api/ {
|
|
proxy_pass http://222.128.1.157:18827/;
|
|
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_connect_timeout 120s;
|
|
proxy_send_timeout 120s;
|
|
proxy_read_timeout 120s;
|
|
proxy_buffering on;
|
|
proxy_buffer_size 128k;
|
|
proxy_buffers 8 256k;
|
|
proxy_busy_buffers_size 512k;
|
|
}
|
|
|
|
# MCP 服务
|
|
location /mcp/ {
|
|
proxy_pass http://127.0.0.1:8900/;
|
|
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 Connection '';
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
chunked_transfer_encoding on;
|
|
proxy_connect_timeout 75s;
|
|
proxy_send_timeout 300s;
|
|
proxy_read_timeout 300s;
|
|
gzip off;
|
|
add_header X-Accel-Buffering no;
|
|
}
|
|
|
|
# 健康检查
|
|
location /health {
|
|
return 200 'ok';
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# 默认返回 404
|
|
location / {
|
|
return 404 '{"error": "Not Found", "message": "Please use /api/ prefix"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
}
|