ALIEZ 1 miesiąc temu
rodzic
commit
81cdc0feda
1 zmienionych plików z 10 dodań i 0 usunięć
  1. 10 0
      next.config.ts

+ 10 - 0
next.config.ts

@@ -8,6 +8,16 @@ const remittanceProxyTarget =
   process.env.API_PROXY_TARGET_REMITTANCE?.replace(/\/$/, "") ?? "";
 
 const nextConfig: NextConfig = {
+  /**
+   * 放在 Nginx/Caddy 等反代后面时开启:用客户端的 Host / 转发头构造 URL,
+   * 避免 Next 把内部监听端口(如 `next start` 默认的 3000)写进重定向,
+   * 否则浏览器会跳到 `jinclab.com:3000` 且公网 3000 通常不可达。
+   * 反代需传:`Host`、`X-Forwarded-Proto`(及按需 `X-Forwarded-Host`),且不要把上游端口写进 Host。
+   */
+  // Next 16 类型里未声明,运行时仍读取(见 node_modules/next/.../resolve-routes.js)
+  experimental: {
+    trustHostHeader: true,
+  } as NextConfig["experimental"],
   async rewrites() {
     const rewrites = [];
     if (apiProxyTarget && /^https?:\/\//i.test(apiProxyTarget)) {