WebSocket连接到url / _next / webpack-hmr'失败。

3

我正在使用next.js 12版本部署网页,但在部署时控制台会出现警告

websocket.js?a9be:45 WebSocket连接到'wss://eteaga.com/_next/webpack-hmr'失败:

在本地主机上没有任何警告或问题。是否需要添加一些配置来适应next.js的新版本?


可能值得看一下 https://github.com/vercel/next.js/issues/30491。 - juliomalves
你在使用Docker、Apache、Nginx吗? - Bogdan Le
1个回答

1

你需要为websockets定义一个新的location块,并在那里添加nginx配置以升级连接:

        location /_next/webpack-hmr {

        # I assumed my server is running on port 3000 on localhost
        proxy_pass http://localhost:3000/_next/webpack-hmr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接