在 Apache mod_proxy_wstunnel 后面使用 go-websocket

注意:更新了配置并向 websocket 路径添加了尾部斜杠。还是一样的问题


是否可以在带有mod_proxy_wstunnel的 Apache 反向代理后面使用go-websocket?


我尝试过但未能使事情正常进行。


我尝试在 Apache 反向代理后面使用Chat 示例(启用了mod_proxy_wstunnel)。它不起作用。代理是成功的,而 websocket 部分根本不起作用。


我的 Apache 配置与此类似:


<VirtualHost *:80>

    DocumentRoot /var/www/foobar

    ServerName foobar.com

    ProxyPass / http://localhost:8080/

    ProxyPassReverse / http://localhost:8080/

    ProxyPass /ws/ ws://localhost:8080/ws/

    ProxyPassReverse /ws/ ws://localhost:8080/ws/

    ErrorLog logs/error_log-foobar

    CustomLog logs/access_log-foobar common

    LogLevel debug

</VirtualHost>

当然,我在端口 8080 上运行聊天服务器。我已经使用 SSH 隧道对其进行了测试,并且一切正常。然后我转到了 Apache。


我第一次尝试时,javascript 控制台抱怨这个:


NetworkError: 403 Forbidden - http://foobar.com/ws/

该请求似乎停留在原点检查上。然后我在注释掉原点检查后再次尝试,它得到了这个:


NetworkError: 400 Bad Request - http://foobar.com/ws/

聊天服务器似乎根本没有收到升级请求。


我应该如何调试这个?我应该从哪里开始寻找?


繁花如伊
浏览 238回答 2
2回答

回首忆惘然

我在 CentOS 7 上的 Apache 2.4.18 后面使用 Go 安全 WebSocket (wss://) 服务器。以下是设置:确保系统有 mod_proxy_wstunnel:# 查找 /usr/lib64/httpd/modules/ | grep ws/usr/lib64/httpd/modules/mod_proxy_wstunnel.so在 00-proxy.conf 中添加以下行:# vim /etc/httpd/conf.modules.d/00-proxy.confLoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so重启阿帕奇:# systemctl 重启 httpd检查设置:# httpd -M | grep -iE '代理'&nbsp;proxy_module (shared)&nbsp;proxy_fcgi_module (shared)&nbsp;proxy_http_module (shared)&nbsp;proxy_wstunnel_module (shared)编辑 httpd-vhosts.conf:# vim /etc/httpd/conf.d/httpd-vhosts.conf<VirtualHost *:443>&nbsp; &nbsp; ServerName go.mydomain.com:443&nbsp; &nbsp; ProxyPreserveHost On&nbsp; &nbsp; ProxyRequests off&nbsp; &nbsp; SSLProxyEngine On&nbsp; &nbsp; SSLCertificateFile "/etc/pki/tls/certs/mydomain.com/mydomain.crt"&nbsp; &nbsp; SSLCertificateKeyFile "/etc/pki/tls/certs/mydomain.com/mydomain.key"&nbsp; &nbsp; ### The configured ProxyPass and ProxyPassMatch rules are checked&nbsp; &nbsp; ### in the order of configuration. The first rule that matches wins.&nbsp; &nbsp; ProxyPassMatch ^/(ws(/.*)?)$ wss://192.168.0.1:443/$1&nbsp; &nbsp; ProxyPass / https://192.168.0.1:443/&nbsp; &nbsp; ProxyPassReverse / https://192.168.0.1:443/&nbsp; &nbsp; ErrorLog "/var/log/httpd/go.mydomain.com-error_log"&nbsp; &nbsp; CustomLog "/var/log/httpd/go.mydomain.com-access_log" common</VirtualHost><VirtualHost *:80>&nbsp; &nbsp; ServerName go.mydomain.com:80&nbsp; &nbsp; ProxyPreserveHost On&nbsp; &nbsp; ProxyRequests off&nbsp; &nbsp; ###&nbsp; &nbsp; ProxyPassMatch ^/(ws(/.*)?)$ ws://192.168.0.1:80/$1&nbsp; &nbsp; ProxyPass / http://192.168.0.1:80/&nbsp; &nbsp; ProxyPassReverse / http://192.168.0.1:80/&nbsp; &nbsp; ErrorLog "/var/log/httpd/go.mydomain.com-error_log"&nbsp; &nbsp; CustomLog "/var/log/httpd/go.mydomain.com-access_log" common</VirtualHost>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go