繁体   English   中英

在Apache mod_proxy_wstunnel后面使用go-websocket

[英]Using go-websocket behind Apache mod_proxy_wstunnel

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

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

我试过并且没能让事情奏效。

我尝试使用Apache反向代理背后的聊天示例 (启用了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/

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

我该怎么调试呢? 我应该从哪里开始寻找?

感谢大家! 在上面提出几个建议后,我找到了解决方案。

对于可能有类似问题的人,这是我的问题的解决方案:

  1. 正如Aralo建议的那样,必须将尾随斜杠添加到WebSocket路径中(在我的例子中:“/ ws /”)。 看起来Apache只会使用有效的GET请求来处理WebSocket。

  2. 詹姆斯亨斯特里奇是对的。 ProxyPass的顺序相关。 / ws /的ProxyPass必须放在/ line之前。

  3. 在查阅聊天示例代码后,我在函数ServeWs()中找到了原始检查并删除了。

现在一切都有效。

感谢covener ,阅读日志确实有帮助。

我在CentOS 7上使用Apache 2.4.18后面的Go安全WebSocket(wss://)服务器。以下是设置:

确保系统具有mod_proxy_wstunnel:

#find / 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 restart 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>

暂无
暂无

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

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