解决官网混合SSR加载慢

This commit is contained in:
dxin
2025-12-31 11:57:15 +08:00
parent b60f06476a
commit cf14d8a6db

View File

@@ -1,6 +1,6 @@
upstream official_backend { upstream official_backend {
server 10.0.0.5:3000; # 机器A的内网地址 server 10.0.0.5:3000;
server 10.0.0.15:3000; # 机器B的内网地址 server 10.0.0.15:3000;
} }
upstream new_official_backend { upstream new_official_backend {
@@ -54,37 +54,58 @@ server {
access_log /data/tengine/logs/lessie.ai.access.log official_log; access_log /data/tengine/logs/lessie.ai.access.log official_log;
error_log /data/tengine/logs/lessie.ai.error.log; error_log /data/tengine/logs/lessie.ai.error.log;
# 1. 新框架的业务页面逻辑 # SSR 场景放大超时
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
# 拦截 PHP / WordPress 扫描
location ~* \.php$ {
return 444;
}
# 新框架的业务页面逻辑
location ~ "^/([a-z]{2}(-[a-z]{2})?/)?(influencer-marketing|b2b-lead-generation|investor-scouting|recruiting|partnerships)" { location ~ "^/([a-z]{2}(-[a-z]{2})?/)?(influencer-marketing|b2b-lead-generation|investor-scouting|recruiting|partnerships)" {
proxy_pass http://new_official_backend; proxy_pass http://new_official_backend;
proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} }
# 2. 静态资源分流 (核心逻辑) # Next.js 静态 & data
location ~ ^/(_next/|__nuxt/|.*\.json) { location ^~ /_next/ {
# 默认给老项目 (3000端口) proxy_pass http://new_official_backend;
set $target_upstream http://official_backend; proxy_http_version 1.1;
# 只有当来源页面 (Referer) 明确包含新项目的关键字时,才改发到 3003
if ($http_referer ~* "(influencer-marketing|b2b-lead-generation|investor-scouting|recruiting|partnerships)") {
set $target_upstream http://new_official_backend;
}
proxy_pass $target_upstream;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} }
# 反向代理到后端服务器渲染的nxut项目3000端口(老框架的完整页面) # Nuxt 静态资源
location / { location ^~ /_nuxt/ {
proxy_pass http://official_backend; proxy_pass http://official_backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
} }
# Nuxt data / 其他 json
location ~ \.json$ {
proxy_pass http://official_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# 旧站Nuxt SSR
location / {
proxy_pass http://official_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;
}
location /video/ { location /video/ {
root /data/tengine/html/lessie_official; root /data/tengine/html/lessie_official;
expires 30d; expires 30d;
@@ -101,7 +122,6 @@ server {
proxy_pass http://official_backend; proxy_pass http://official_backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
add_header Cache-Control "no-cache, no-store, must-revalidate" always; add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always; add_header Pragma "no-cache" always;
@@ -116,9 +136,31 @@ server {
add_header Expires 0 always; add_header Expires 0 always;
} }
# 第三方邮件SendGrid平台调用 # 第三方邮件件平台调国内email
location /prod-api/webhook/ { location /prod-api/webhook/ {
proxy_pass http://129.204.158.54:4997/webhook/; proxy_pass http://129.204.158.54:4997/webhook/;
proxy_set_header Host 129.204.158.54;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_intercept_errors off;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection keep-alive;
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,X-Requested-With,Accept,Origin' always;
if ($request_method = OPTIONS ) {
return 204;
}
}
# 第三方邮件SendGrid平台调用
location /prod-api/webhook/us {
proxy_pass http://10.0.0.10:4997/webhook/us;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -139,8 +181,8 @@ server {
} }
# 第三方支付平台调用 # 第三方支付平台调用
location /payment/ / { location /payment/ {
proxy_pass http://129.204.158.54:8090; proxy_pass http://10.0.0.8:8090;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;