V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cutedogspark
V2EX  ›  问与答

项目反向代理出错

  •  
  •   cutedogspark · 12 天前 · 616 次点击

    做了一个小项目,用的 node ,前后端分离,然后在部署前端的反向代理的时候,提示 Invalid Host header 问了 ai 说是问题出在服务器的 CORS(跨域资源共享)设置中,但是配置了白名单还是无用,求救各位 v 友。 和 cors 相关的代码:

    const io = socketIo(server, {
      cors: {
        origin: "*",  // 改用最宽松的 CORS 配置
        methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
        allowedHeaders: ["Content-Type", "Authorization"],
        credentials: true
      },
      allowEIO3: true, // 添加兼容性选项
      transports: ['websocket', 'polling'] // 显式指定传输方式
    });
    
    // 中间件
    app.use(cors({
      origin: "*", // 改用最宽松的 CORS 配置
      methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
      allowedHeaders: ["Content-Type", "Authorization"],
      credentials: true
    }));
    app.use(express.json());
    
    2 条回复    2025-04-17 07:56:56 +08:00
    MHPSY
        1
    MHPSY  
       11 天前
    反向代理使用的什么,使用的 nginx 吗,不反向代理直连可以通吗
    cutedogspark
        2
    cutedogspark  
    OP
       8 天前 via Android
    @MHPSY #1 对的 nginx ,ip+端口可以正常访问
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1071 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 23:34 · PVG 07:34 · LAX 16:34 · JFK 19:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.