【发布时间】:2021-11-02 11:25:06
【问题描述】:
我已经在我的带有 Gunicorn 的 Ubuntu 20.04 服务器上部署了一个带有多个 API 的 Django rest 框架服务,一切正常,但是来自服务器外部的 PATCH 请求没有收到响应,尽管应用程序接收到请求并完全处理它。
我什至用 Django runserver 对其进行了测试,但问题仍然存在,与 Gunicorn 无关。
重现步骤:
- 在服务器上,我们创建一个新的 Django 应用程序:
ssh to_my@server
python3 -m pip install django
django-admin mytest
cd mytest
python3 manage.py runserver 0.0.0.0:9999
- 在尝试向应用程序发送请求的服务器上:
ssh to_my@server
curl --request GET localhost:9999/ # this works fine and we can see the response
curl --request PATCH localhost:9999/ # this works fine too
- 在另一台机器上试试这些:
# on my local machine
curl --request GET IP:9999/ # this works fine
curl --request PATCH IP:9999/ # **** this will get a `curl: (56) Recv failure: Connection reset by peer` after some times
响应永远不会到达,尽管在控制台中你可以看到请求已被完全接收并且 Django 没有问题:
Invalid HTTP_HOST header: '207.154.246.122:9999'. You may need to add '207.154.246.122' to ALLOWED_HOSTS.
Bad Request: /
[02/Nov/2021 11:18:25] "PATCH / HTTP/1.1" 400 62827
请忽略与我们的问题无关的异常。
请注意,这是一个最小部署,我通过 HTTP 而不是 HTTPS 提供服务,并且端口已经打开,我知道我可以使用 PUT 而不是 PATCH 方法,并且我不使用 NGINX 直接转发它。
我的问题是:是什么导致了这种行为?这是操作系统吗?以及如何解决这个问题并接收来自我的 PATCH 请求的响应?
【问题讨论】:
标签: python django linux ubuntu