Skip to content

[Bug] x-forwarded-host not match 错误 #6537

@ecator

Description

@ecator

📦 部署方式

Docker

📌 软件版本

v2.16.0

💻 系统环境

Ubuntu

📌 系统版本

24.04.1 LTS

🌐 浏览器

Firefox

📌 浏览器版本

139.0.4 (64 位)

🐛 问题描述

docker部署,通过nginx反代后前端报下面的错误:

Image

当然聊天也不行,直接显示....

Image

后台查日志好像有下面的错误:

app-1  | `x-forwarded-host` header with value `127.0.0.1:3002` does not match `origin` header with value `这个地方是我的域名` from a forwarded Server Actions request. Aborting the action.
app-1  | Error: Invalid Server Actions request.
app-1  |     at rm (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:5881)
app-1  |     at rq (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:1255)
app-1  |     at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:3935
app-1  |     at AsyncLocalStorage.run (node:async_hooks:338:14)
app-1  |     at Object.wrap (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:13:16239)
app-1  |     at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:3825
app-1  |     at AsyncLocalStorage.run (node:async_hooks:338:14)
app-1  |     at Object.wrap (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:13:15487)
app-1  |     at rW (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:3752)
app-1  |     at no.render (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:7725)

nginx非常简单就是下面(一直用的这个没有问题的,至少v2.15.8是ok的):

proxy_buffering off;
  location / {
    proxy_pass http://127.0.0.1:3002;
  }

📷 复现步骤

docker部署2.16.0版本,然后通过nginx反代

🚦 期望结果

能正常使用

📝 补充信息

2.15.8没有这个问题,而且其他配置都没有动过,搜索了下好像是Next.js有这个问题?但是我看了下代码又没有这个配置,难道要加上?
https://raddy.dev/blog/next-js-14-0-2-x-forwarded-host-header-with-value-localhost3000-does-not-match-origin-fix/

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions