简体   繁体   English

如何通过 unix 套接字将 HTTP 和 Websockets 从 Apache 代理到 Gunicorn?

[英]How to proxy HTTP and Websockets from Apache to Gunicorn over unix sockets?

My Setup already works over TCP with these two lines in my virtualhost:我的安装程序已经在我的虚拟主机中使用这两行通过 TCP 工作:

ProxyPassMatch ^/ws/.*$ ws://localhost:8000/
ProxyPass / http://localhost:8000/

Now I want to use unix sockets.现在我想使用unix套接字。 So I prepended unix:$SOCKETPATH|所以我在unix:$SOCKETPATH|前面unix:$SOCKETPATH| and removed the port:并删除了端口:

ProxyPassMatch ^/ws/.*$ unix:/run/myapp.sock|ws://localhost/
ProxyPass / unix:/run/myapp.sock|http://localhost/

It works for HTTP, but websocket connections fail.它适用于 HTTP,但 websocket 连接失败。 I tried variations of the right side in the websockets line, eg:我在 websockets 行中尝试了右侧的变体,例如:

ProxyPassMatch ^/ws/.*$ unix:/run/myapp.sock|ws:///
ProxyPassMatch ^/ws/.*$ unix:/run/myapp.sock|ws://

Besides getting it to work, I'd like to understand why there is the part after the pipe (|) needed anyways?除了让它工作之外,我想了解为什么仍然需要管道 (|) 后面的部分? After all, Apache should only need to know the unix socket path, shouldn't it?毕竟,Apache 应该只需要知道 unix 套接字路径,不是吗? The Apache documentation on ProxyPass does not explain this. ProxyPass上的Apache 文档没有解释这一点。

These similar questions did not help:这些类似的问题没有帮助:

I upgraded the Debian Apache packets from 2.4.38-3+deb10u4 (stable) to 2.4.46-4~bpo10+1 (backports) and now it works.我将 Debian Apache 数据包从 2.4.38-3+deb10u4(稳定)升级到 2.4.46-4~bpo10+1(反向移植),现在它可以工作了。 The Apache changelog mentions multiple changes to websockets. Apache 更改日志提到了对 websockets 的多项更改。 I suppose this change might have been the problem:我想这个变化可能是问题所在:

mod_proxy_wstunnel: Leave Upgrade requests handling to mod_proxy_http,
allowing for (non-)Upgrade negotiation with the origin server.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM