在Apache mod_proxy_wstunnel后面使用go websocket
注意:更新了配置并将尾部斜杠添加到websocket路径。还是一样的问题 可以在Apache反向代理后面使用吗 我试过了,但没有成功 我尝试在Apache反向代理(启用)后使用。但它不起作用。代理成功了,而websocket部分根本不起作用 我的Apache配置与此类似:在Apache mod_proxy_wstunnel后面使用go websocket,apache,websocket,go,mod-proxy,Apache,Websocket,Go,Mod Proxy,注意:更新了配置并将尾部斜杠添加到websocket路径。还是一样的问题 可以在Apache反向代理后面使用吗 我试过了,但没有成功 我尝试在Apache反向代理(启用)后使用。但它不起作用。代理成功了,而websocket部分根本不起作用 我的Apache配置与此类似: <VirtualHost *:80> DocumentRoot /var/www/foobar ServerName foobar.com ProxyPass / http://localh
<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>
该请求似乎在原产地检查时受阻。
然后我在注释掉原点检查后再次尝试,结果如下:
NetworkError: 400 Bad Request - http://foobar.com/ws/
聊天服务器似乎根本没有收到升级请求
我应该如何调试它?
我应该从哪里开始找呢?谢谢大家!在采纳了以上几条建议后,我找到了解决办法 对于可能有类似问题的人,以下是我问题的解决方案:
谢谢,阅读日志确实有帮助。我正在CentOS 7上使用Apache 2.4.18背后的Go-secure WebSocket(wss://)服务器。以下是设置: 确保系统具有mod\u proxy\u wstunel: #查找/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.conf
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
重新启动Apache:
#systemctl重启httpd
检查设置:
#httpd-M | grep-iE“代理”
proxy_module (shared)
proxy_fcgi_module (shared)
proxy_http_module (shared)
proxy_wstunnel_module (shared)
编辑httpd vhosts.conf:
#vim/etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:443>
ServerName go.mydomain.com:443
ProxyPreserveHost On
ProxyRequests off
SSLProxyEngine On
SSLCertificateFile "/etc/pki/tls/certs/mydomain.com/mydomain.crt"
SSLCertificateKeyFile "/etc/pki/tls/certs/mydomain.com/mydomain.key"
### The configured ProxyPass and ProxyPassMatch rules are checked
### in the order of configuration. The first rule that matches wins.
ProxyPassMatch ^/(ws(/.*)?)$ wss://192.168.0.1:443/$1
ProxyPass / https://192.168.0.1:443/
ProxyPassReverse / https://192.168.0.1:443/
ErrorLog "/var/log/httpd/go.mydomain.com-error_log"
CustomLog "/var/log/httpd/go.mydomain.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName go.mydomain.com:80
ProxyPreserveHost On
ProxyRequests off
###
ProxyPassMatch ^/(ws(/.*)?)$ ws://192.168.0.1:80/$1
ProxyPass / http://192.168.0.1:80/
ProxyPassReverse / http://192.168.0.1:80/
ErrorLog "/var/log/httpd/go.mydomain.com-error_log"
CustomLog "/var/log/httpd/go.mydomain.com-access_log" common
</VirtualHost>
ServerName go.mydomain.com:443
代理主机
代理请求关闭
SSLProxyEngine打开
SSLCertificateFile“/etc/pki/tls/certs/mydomain.com/mydomain.crt”
SSLCertificateKeyFile“/etc/pki/tls/certs/mydomain.com/mydomain.key”
###已检查配置的ProxyPass和ProxyPassMatch规则
###按照配置的顺序。匹配的第一条规则获胜。
ProxyPassMatch^/(ws(/.*))$wss://192.168.0.1:443/$1
ProxyPass/https://192.168.0.1:443/
ProxyPassReverse/https://192.168.0.1:443/
ErrorLog“/var/log/httpd/go.mydomain.com-error\u log”
CustomLog“/var/log/httpd/go.mydomain.com-access\u log”通用
ServerName go.mydomain.com:80
代理主机
代理请求关闭
###
ProxyPassMatch^/(ws(/.*)$ws://192.168.0.1:80/$1
ProxyPass/http://192.168.0.1:80/
ProxyPassReverse/http://192.168.0.1:80/
ErrorLog“/var/log/httpd/go.mydomain.com-error\u log”
CustomLog“/var/log/httpd/go.mydomain.com-access\u log”通用
尾随斜杠是否重要?只是猜测……不。我想不是。我刚刚试着给所有东西加上尾随斜杠。问题仍然是一样的。我想两台服务器都有日志记录,他们怎么说?表示ProxyPass
指令按顺序匹配,因此您的/ws/
指令可能被/
指令所掩盖。如果你改变订单,你会有不同的行为吗?谢谢!顺序很重要。你能发布你的最终解决方案吗。你的问题包含了你在回答中提到的所有内容。所以,我有点困惑。这就是我最终解决方案的完整描述。你想让我在这里发布实际配置吗?或者你觉得哪一部分很难理解?@KoalaYeung你也可以发布你的apache配置文件吗?我们需要看看你在哪一条路径上编辑了哪一个文件,以及它的最终外观,以便我们可以将我们的文件与你的文件进行比较。请尽快发布,因为我在搜索解决方案时已经浪费了2天时间。你自己解决这个问题真是太好了。你能提供这个的源代码吗。。。我的电子邮件是veshraj。joshi1@gmail.comThis这个答案对我很有用,因为我必须在没有任何/path/的情况下反转代理wss和https请求来区分它们。ProxyPassMatch派上了用场。
<VirtualHost *:443>
ServerName go.mydomain.com:443
ProxyPreserveHost On
ProxyRequests off
SSLProxyEngine On
SSLCertificateFile "/etc/pki/tls/certs/mydomain.com/mydomain.crt"
SSLCertificateKeyFile "/etc/pki/tls/certs/mydomain.com/mydomain.key"
### The configured ProxyPass and ProxyPassMatch rules are checked
### in the order of configuration. The first rule that matches wins.
ProxyPassMatch ^/(ws(/.*)?)$ wss://192.168.0.1:443/$1
ProxyPass / https://192.168.0.1:443/
ProxyPassReverse / https://192.168.0.1:443/
ErrorLog "/var/log/httpd/go.mydomain.com-error_log"
CustomLog "/var/log/httpd/go.mydomain.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName go.mydomain.com:80
ProxyPreserveHost On
ProxyRequests off
###
ProxyPassMatch ^/(ws(/.*)?)$ ws://192.168.0.1:80/$1
ProxyPass / http://192.168.0.1:80/
ProxyPassReverse / http://192.168.0.1:80/
ErrorLog "/var/log/httpd/go.mydomain.com-error_log"
CustomLog "/var/log/httpd/go.mydomain.com-access_log" common
</VirtualHost>