gpt4 book ai didi

WebSocket connection to Docker container via Apache reverse proxy issue(通过Apache反向代理问题连接到Docker容器的WebSocket)

转载 作者:bug小助手 更新时间:2023-10-24 17:55:17 31 4
gpt4 key购买 nike



I am facing difficulties setting up a WebSocket connection through an Apache reverse proxy to a WebSocket server running inside a Docker container. Here's the scenario:

我遇到了困难,无法通过Apache反向代理建立到在Docker容器中运行的WebSocket服务器的WebSocket连接。以下是场景:



  • WebSocket server: The WebSocket server is hosted inside a Docker container.

  • Docker container configuration: The WebSocket server in the Docker container is configured to listen for WebSocket connections on a specific path, e.g., /ws/chat/1694406657943/.

  • Apache reverse proxy: I have configured Apache as a reverse proxy to forward WebSocket requests to the WebSocket server inside the Docker container.
    Issue:
    When attempting to connect to ws://abc.com/ws/chat/1694406657943/, I encounter the error message "WebSocket connection failed."


What I've already tried:

我已经尝试过了:



  • Confirmed that the WebSocket server inside the Docker container is running and correctly configured to handle WebSocket connections on the specified path.

  • Checked Apache error logs, but I couldn't find any relevant errors or warnings.

  • Ensured that the Docker container's port is correctly exposed to the host machine.

  • Verified that the WebSocket server works correctly when accessed directly on the host machine.


I'm looking for guidance on how to troubleshoot and resolve this WebSocket connection issue through the Apache reverse proxy.

我正在寻找有关如何通过Apache反向代理对WebSocket连接问题进行故障排除和解决的指导。


<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com


ServerName abc.com
ServerAdmin [email protected]

ProxyRequests Off

<Proxy *>
Require all granted
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/


ProxyPass /ws ws://127.0.0.1:8000/
ProxyPassReverse /ws ws://127.0.0.1:8000/
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/abc.com.error.log
CustomLog ${APACHE_LOG_DIR}/abc.com.access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

web error


更多回答
优秀答案推荐

After checking the Docker log as well as the Apache log, I managed to fix it by changing the Apache WebSocket configuration according to the web URL request

在检查了Docker日志和Apache日志之后,我根据Web URL请求更改了ApacheWebSocket配置,从而设法修复了它


ProxyPass /ws ws://127.0.0.1:8000/ws
ProxyPassReverse /ws ws://127.0.0.1:8000/ws

更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com