openbsd httpd with gunicorn+uvicorn -- Remote protocol error : illegal request line

openbsd httpd with gunicorn+uvicorn -- Remote protocol error : illegal request line

我的 Web 部署设置是在 openBSD 上,由前面的 httpd 和 guicorn + uvicorn 作为后端引擎组成,通过 unix 套接字连接。

从 httpd 的请求通过 unix 套接字转发到 gunicorn 的意义上说,该设置有效。但是,gunicorn/uvicorn 无法理解传入的 http 请求。 错误堆栈

[2021-11-22 22:52:17 +0530] [1631] [WARNING] Invalid HTTP request received.
Traceback (most recent call last):
  File "/home/shared/Builds/Python-3.10.0/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
    event = self.conn.next_event()
  File "/home/shared/Builds/Python-3.10.0/lib/python3.10/site-packages/h11/_connection.py", line 443, in next_event
    exc._reraise_as_remote_protocol_error()
  File "/home/shared/Builds/Python-3.10.0/lib/python3.10/site-packages/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
    raise self
  File "/home/shared/Builds/Python-3.10.0/lib/python3.10/site-packages/h11/_connection.py", line 425, in next_event
    event = self._extract_next_receive_event()
  File "/home/shared/Builds/Python-3.10.0/lib/python3.10/site-packages/h11/_connection.py", line 367, in _extract_next_receive_event
    event = self._reader(self._receive_buffer)
  File "/home/shared/Builds/Python-3.10.0/lib/python3.10/site-packages/h11/_readers.py", line 68, in maybe_read_from_IDLE_client
    raise LocalProtocolError("illegal request line")
h11._util.RemoteProtocolError: illegal request line

我不确定非法请求行的潜在原因是什么。

httpd 不支持 http 代理。 它支持提供静态文件以及 FastCGI。错误消息表明您的 httpd 尝试使用 FastCGI.

与 gunicorn 通信

因此,如果您坚持使用 httpd,找到一种使用 FastCGI 服务器而不是 WSGI (gunicorn) 来 运行 您的应用程序的方法。许多年前 flup 是一个流行的选择。

或者,只需使用 Nginx 而不是 httpd