nextjs 配置避免 http 服务器超时

ass*_*bss 5 next.js

我有一个由 nginx 代理的 nextjs 项目。我正在使用由 nextjs 本身提供的休息 api,需要超过 2 分钟。

我得到的第一个错误是 nginx 504 超时,所以我添加了一些额外的指令:

proxy_connect_timeout 600s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
Run Code Online (Sandbox Code Playgroud)

然后错误代码变为 502。查看 proxy_error_log 文件,错误是

 upstream prematurely closed connection while reading response header from upstream.
Run Code Online (Sandbox Code Playgroud)

在我的项目中,我没有明确使用express或任何其他服务器,所以我不知道如何设置http服务器超时。有什么方法可以从 next.config.js 文件或全局设置 Node js 的超时吗?

gaz*_*rgo 1

来自secret104278的回答:

...这个问题只出现在node12中,而不出现在node14中。这是因为node12中默认超时是2分钟,而node14中没有超时

在带有node12的next.js中解决这个问题的唯一方法是使用--http-server-default-timeout类似的东西NODE_OPTIONS='--http-server-default-timeout=0' next start

希望这对任何人都有帮助