Pixiv - KiraraShss
next.js 解决 `x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request
178 字
1 分钟
next.js 解决 `x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request
在 GitHub codespaces 上开发 next.js 项目,端口穿透出来后访问,结果报错:
`x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request.解决方案:
- 如果需要,首先更新 next.js 。参见 https://nextjs.org/docs/messages/version-staleness ,运行命令:
pnpm add next@latest这应当是不会报错了。但如果您像笔者一样使用了 ppr: true ,就应当使用 canary 版本,不然后续可能会出错。
- 修改
next.config.js,添加experimental.serverActions.allowedOrigins。
例如我这里:
import type { NextConfig } from 'next';
const nextConfig: NextConfig = { /* config options here */ experimental: { serverActions: { allowedOrigins: [ 'localhost:3000', // localhost 'super-duper-space-*****-*****-3000.app.github.dev', // Codespaces ], }, ppr: true, }, images: { remotePatterns: [ { hostname: 'avatar.vercel.sh', }, ], },};
export default nextConfig;然后重新启动后就能成功访问了。
支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!
next.js 解决 `x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request
https://www.0x3f.foo/posts/xforwardedhost/ 相关文章 智能推荐
1
迁站记:自旧域至新域,自 Jekyll 至 Astro
展览厅 记一次博客由旧域迁移至新域,并由 Jekyll 更易为 Astro 之经过与所感。
2
How to Create a React MUI Project from Scratch
实验室 2024-04-03
3
解决macOS报错 yld[1515]: Symbol not found
实验室 2025-01-28
4
Chrome 将我的后台登录页标记为危险:一次 Safe Browsing 误判排查记录
实验室 记录一次后台登录页面被 Chrome 标记为 Social Engineering 的排查与修复全过程,以及如何避免再次误判。
5
使用AI开发纯血鸿蒙arkTS应用的进阶指南(VSCode+Copilot)
实验室 2026-02-16
随机文章 随机推荐
无穷大?