注意:更新了配置,并在websocket路径中添加了斜杠。 还是同样的问题
是否可以在带有mod_proxy_wstunnel的Apache反向代理后面使用go- websocket?
我尝试并未能使事情正常进行。
我尝试在Apache反向代理(启用了mod_proxy_wstunnel)后面使用Chat示例。而且它不起作用。代理是成功的,而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/
似乎聊天服务器根本没有收到升级请求。
我应该如何调试呢?我应该从哪里开始寻找?
我在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.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>