curl命令在从stdin上传文件时挂在nginx服务器上



首先,我正在尝试为我的node.js应用程序实现一个repl服务器,我在这个要点的帮助下创建了它。一切都很好,我可以在localhost:中使用此命令连接到我的repl服务器

$ curl -sSNT. localhost:8000
Welcome to the Fun House
> echo me
echo me
> echo me again
echo me again
> bye
bye
> ^C

但是当我尝试使用nginx作为反向代理时,这个命令被挂起,并且没有显示任何输出:

$ curl -sSNT. test.localhost:8083 -I
HTTP/1.1 100 Continue
It hangs forever.

重现问题的步骤:

  1. git clone https://github.com/mostafa8026/nginx-repl-curl.git
  2. cd nginx-repl-curl
  3. docker-compose build
  4. 将test.localhost添加到主机
127.0.0.1       localhost test.localhost
  1. docker-compose up -d
  2. 主要问题:curl -sSNT. test.localhost:8083 -I

编辑

如答案中所述,我们可以尝试写入,然后按Ctrl+D,但它会关闭连接,作为repl服务器,主要目的是保持连接打开并在命令行中发送命令,如下所示:

$ curl -sSNT. localhost:8000
Welcome to the Fun House
> echo me
echo me
> echo me again
echo me again
> bye
bye
> ^C

不是这样的:

curl -sSNT. test.localhost:8083 -I
HTTP/1.1 100 Continue
echo me
HTTP/1.1 200 OK
Server: nginx/1.21.1
Date: Sat, 09 Apr 2022 12:58:37 GMT
Content-Type: multipart/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
Welcome to the Fun House
> echo me
> Ended
It hangs here
^C

它挂起了,因为它正在等待您向stdin 写入一些内容(要上传的文件(

写一些命中enter然后命中ctrl+D的内容

答案测试

$ curl -sSNT. test.localhost:8083 -I
HTTP/1.1 100 Continue
Here's a test 
mostafa8026    
HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Sat, 09 Apr 2022 11:41:35 GMT
Content-Type: multipart/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
Welcome to the Fun House
> Here's a test 
mostafa8026
> Ended

最新更新