我目前托管着一个用FastifyJS制作的API,并通过一个用Apache制做的反向代理.如果我直接向我的 node 服务器发出请求,一切都会正常工作,然而,对于apache(我也try 了nginx),似乎不会将响应发送到我的客户端.在判断了Apache访问日志(log)和Fastify详细模式日志(log)后,我的代理似乎没有收到来自FastifyJS的响应.

Logs from FastifyJS (verbose):

{"level":30,"time":1706742990703,"pid":1358,"hostname":"debian","reqId":"req-2","req":{"method":"POST","url":"/files/create","hostname":"127.0.0.1:3500","remoteAddress":"127.0.0.1","remotePort":35272},"msg":"incoming request"}
{"level":30,"time":1706742990925,"pid":1358,"hostname":"debian","reqId":"req-2","res":{"statusCode":200},"responseTime":222.1608750000014,"msg":"request completed"}
{"level":30,"time":1706742990964,"pid":1358,"hostname":"debian","reqId":"req-3","req":{"method":"PUT","url":"/files/uploadChunk?transferkey=azezaqsdcdsq&chunk=0","hostname":"127.0.0.1:3500","remoteAddress":"127.0.0.1","remotePort":35272},"msg":"incoming request"}
Uploaded chunk (transferKey: azezaqsdcdsq, chunk: 0): chunkPos: 0
{"level":30,"time":1706742999872,"pid":1358,"hostname":"debian","reqId":"req-3","res":{"statusCode":201},"responseTime":8908.116479000004,"msg":"request completed"}
{"level":30,"time":1706742999908,"pid":1358,"hostname":"debian","reqId":"req-4","req":{"method":"PUT","url":"/files/uploadChunk?transferkey=azezaqsdcdsq&chunk=1","hostname":"127.0.0.1:3500","remoteAddress":"127.0.0.1","remotePort":36536},"msg":"incoming request"}
Uploaded chunk (transferKey: azezaqsdcdsq, chunk: 1): chunkPos: 1
{"level":30,"time":1706743001925,"pid":1358,"hostname":"debian","reqId":"req-4","res":{"statusCode":201},"responseTime":2017.0185090000014,"msg":"request completed"}

Logs from Apache access:

192.168.1.* - - [01/Feb/2024:00:16:30 +0100] "POST /files/create HTTP/1.1" 200 654 "-" "Stend CLI/1.0.1"
192.168.1.* - - [01/Feb/2024:00:16:30 +0100] "PUT /files/uploadChunk?transferkey=azezaqsdcdsq&chunk=0 HTTP/1.1" 201 163 "-" "-"
192.168.1.* - - [01/Feb/2024:00:16:39 +0100] "PUT /files/uploadChunk?transferkey=azezaqsdcdsq&chunk=1 HTTP/1.1" 408 485 "-" "-"

注意:最后一个使用408失败的请求比另一个使用HTTP201成功的请求出现的时间晚几分钟.

Logs from Apache errors (debug):

[Thu Feb 01 00:16:30.702276 2024] [authz_core:debug] [pid 1147:tid 140211841373888] mod_authz_core.c(843): [client 192.168.1.254:50962] AH01628: authorization result: granted (no directives)
[Thu Feb 01 00:16:30.702364 2024] [proxy:debug] [pid 1147:tid 140211841373888] mod_proxy.c(1511): [client 192.168.1.254:50962] AH01143: Running scheme http handler (attempt 0)
[Thu Feb 01 00:16:30.702373 2024] [proxy:debug] [pid 1147:tid 140211841373888] proxy_util.c(2568): AH00942: http: has acquired connection for (127.0.0.1:3500)
[Thu Feb 01 00:16:30.702382 2024] [proxy:debug] [pid 1147:tid 140211841373888] proxy_util.c(2626): [client 192.168.1.254:50962] AH00944: connecting http://127.0.0.1:3500/files/create to 127.
0.0.1:3500
[Thu Feb 01 00:16:30.702389 2024] [proxy:debug] [pid 1147:tid 140211841373888] proxy_util.c(2849): [client 192.168.1.254:50962] AH00947: connected /files/create to 127.0.0.1:3500
[Thu Feb 01 00:16:30.925265 2024] [proxy:debug] [pid 1147:tid 140211841373888] proxy_util.c(2584): AH00943: http: has released connection for (127.0.0.1:3500)
[Thu Feb 01 00:16:30.942604 2024] [authz_core:debug] [pid 1147:tid 140211832981184] mod_authz_core.c(843): [client 192.168.1.254:50967] AH01628: authorization result: granted (no directives)
[Thu Feb 01 00:16:30.942659 2024] [proxy:debug] [pid 1147:tid 140211832981184] mod_proxy.c(1511): [client 192.168.1.254:50967] AH01143: Running scheme http handler (attempt 0)
[Thu Feb 01 00:16:30.942667 2024] [proxy:debug] [pid 1147:tid 140211832981184] proxy_util.c(2568): AH00942: http: has acquired connection for (127.0.0.1:3500)
[Thu Feb 01 00:16:30.942676 2024] [proxy:debug] [pid 1147:tid 140211832981184] proxy_util.c(2626): [client 192.168.1.254:50967] AH00944: connecting http://127.0.0.1:3500/files/uploadChunk?tr
ansferkey=azezaqsdcdsq&chunk=0 to 127.0.0.1:3500
[Thu Feb 01 00:16:30.942686 2024] [proxy:debug] [pid 1147:tid 140211832981184] proxy_util.c(2849): [client 192.168.1.254:50967] AH00947: connected /files/uploadChunk?transferkey=azezaqsdcdsq
&chunk=0 to 127.0.0.1:3500
[Thu Feb 01 00:16:39.872914 2024] [proxy:debug] [pid 1147:tid 140211832981184] proxy_util.c(2584): AH00943: http: has released connection for (127.0.0.1:3500)
[Thu Feb 01 00:16:39.899225 2024] [authz_core:debug] [pid 1148:tid 140212025947840] mod_authz_core.c(843): [client 192.168.1.254:50973] AH01628: authorization result: granted (no directives)
[Thu Feb 01 00:16:39.899319 2024] [proxy:debug] [pid 1148:tid 140212025947840] mod_proxy.c(1511): [client 192.168.1.254:50973] AH01143: Running scheme http handler (attempt 0)
[Thu Feb 01 00:16:39.899351 2024] [proxy:debug] [pid 1148:tid 140212025947840] proxy_util.c(2568): AH00942: http: has acquired connection for (127.0.0.1:3500)
[Thu Feb 01 00:16:39.899363 2024] [proxy:debug] [pid 1148:tid 140212025947840] proxy_util.c(2626): [client 192.168.1.254:50973] AH00944: connecting http://127.0.0.1:3500/files/uploadChunk?tr
ansferkey=azezaqsdcdsq&chunk=1 to 127.0.0.1:3500
[Thu Feb 01 00:16:39.899472 2024] [proxy:debug] [pid 1148:tid 140212025947840] proxy_util.c(2849): [client 192.168.1.254:50973] AH00947: connected /files/uploadChunk?transferkey=azezaqsdcdsq
&chunk=1 to 127.0.0.1:3500
[Thu Feb 01 00:16:39.906992 2024] [proxy:debug] [pid 1148:tid 140212025947840] proxy_util.c(3321): AH02824: http: connection established with 127.0.0.1:3500 (127.0.0.1:3500)
[Thu Feb 01 00:16:39.907053 2024] [proxy:debug] [pid 1148:tid 140212025947840] proxy_util.c(3510): AH00962: http: connection complete to 127.0.0.1:3500 (127.0.0.1)
[Thu Feb 01 00:21:42.000262 2024] [proxy:error] [pid 1148:tid 140212025947840] (70007)The timeout specified has expired: [client 192.168.1.254:50973] AH02608: read request body failed to 127
.0.0.1:3500 (127.0.0.1) from 192.168.1.254 ()
[Thu Feb 01 00:21:42.000332 2024] [proxy_http:error] [pid 1148:tid 140212025947840] [client 192.168.1.254:50973] AH01097: pass request body failed to 127.0.0.1:3500 (127.0.0.1) from 192.168.
1.254 ()
[Thu Feb 01 00:21:42.000341 2024] [proxy:debug] [pid 1148:tid 140212025947840] proxy_util.c(2584): AH00943: http: has released connection for (127.0.0.1:3500)

我也试过使用Nginx,但问题有点类似.直接使用Cloudflare会导致"品牌"的HTTP Bad Gateway错误:

Cloudflare bad gateway

编辑:忘记说这个问题出现在使用Node使用Axios和/或Superagent向服务器发送请求时.我在Postman和使用相同Axios代码的浏览器上没有这个问题(然而,Axios上传文件似乎真的很慢).

推荐答案

不确定我是否成功修复了它,但我的客户端的代码存在问题,该代码向服务器发送了无效的FormData正文.

Node.js相关问答推荐

Azure虚拟机上的JS Express:可疑请求?

Node.js分页返回空数组

MongoDB的方面查询的Postgres类似功能

为什么 mongoose 没有常规数组方法

Mongodb - 在数组数组中查找()

动态设置元数据,无需重复请求 NextJS 13

表达 js 错误处理程序在第一个之后被忽略

错误:无法为 /blog 收集页面数据并且在 object.fetch 处获取失败

ResponseError:键空间ks1不存在

获取数组的至少一个元素包含子字符串的文档

使用中的端口代码:'EADDRINUSE',即使在 kill 命令之后

如何在 Nest.js 中使用查询参数?

添加git信息到create-react-app

使用 pg-promise 进行多行插入

Puppeteer:如何提交表单?

如何在离线时安装 npm 包?

nodejs - 如何读取和输出 jpg 图像?

什么是 JavaScript 中的REPL?

Node.js:如何附加到正在运行的进程并使用控制台调试服务器?

react-native run-android 无法识别