能够将 https 重定向到 http 但不能将 wss 重定向到 ws
Able to redirect https to http but not able to redirect wss to ws
我正在使用网络套接字。在 apache 中,我可以通过在配置文件中进行以下设置来从 https 重定向到 http:
<VirtualHost *:443>
# Common SSL Config
ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
SSLEngine on
# wss redirects to working ws protocol
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
ProxyPass "/" "http://ec2-13-52-248-221.us-west-1.compute.amazonaws.com" retry=0 keepalive=On
</VirtualHost>
但是相同的配置(如上)我改变如下
<VirtualHost *:443>
# Common SSL Config
ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
SSLEngine on
# wss redirects to working ws protocol
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
ProxyPass "/wss" "ws://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080" retry=0 keepalive=On
</VirtualHost>
我无法从 wss 重定向到 ws
如果是 Wss,我在发送请求时使用以下 url:
wss://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080/wss
经过 24 小时的努力终于得到解决方案:这个配置对我有用
首先通过在 windows
的 httpd.conf 文件中启用此模块来加载以下模块
proxy_wstunnel_module modules/mod_proxy_wstunnel.so
在linux中,您可以通过以下命令启用此模块
sudo a2enmod proxy proxy_balancer proxy_wstunnel proxy_http
然后只需将以下行添加到 apache.conf 文件或 httpd-vhosts.conf 文件
RewriteEngine on
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /ws ws://192.168.43.31:8080 retry=0 keepalive=On
ProxyPassReverse /ws ws://192.168.43.31:8080 retry=0
在Javascript中文件的变化是这样的:
if(location.protocol === 'http:'){
var conn = new WebSocket('ws://192.168.43.31/ws');
}
else{
var conn = new WebSocket('wss://192.168.43.31/ws');
}
因此,apache 会将所有包含 ws 的请求重定向回 8080 端口
我正在使用网络套接字。在 apache 中,我可以通过在配置文件中进行以下设置来从 https 重定向到 http:
<VirtualHost *:443>
# Common SSL Config
ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
SSLEngine on
# wss redirects to working ws protocol
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
ProxyPass "/" "http://ec2-13-52-248-221.us-west-1.compute.amazonaws.com" retry=0 keepalive=On
</VirtualHost>
但是相同的配置(如上)我改变如下
<VirtualHost *:443>
# Common SSL Config
ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
SSLEngine on
# wss redirects to working ws protocol
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
ProxyPass "/wss" "ws://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080" retry=0 keepalive=On
</VirtualHost>
我无法从 wss 重定向到 ws
如果是 Wss,我在发送请求时使用以下 url:
wss://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080/wss
经过 24 小时的努力终于得到解决方案:这个配置对我有用
首先通过在 windows
的 httpd.conf 文件中启用此模块来加载以下模块proxy_wstunnel_module modules/mod_proxy_wstunnel.so
在linux中,您可以通过以下命令启用此模块
sudo a2enmod proxy proxy_balancer proxy_wstunnel proxy_http
然后只需将以下行添加到 apache.conf 文件或 httpd-vhosts.conf 文件
RewriteEngine on
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /ws ws://192.168.43.31:8080 retry=0 keepalive=On
ProxyPassReverse /ws ws://192.168.43.31:8080 retry=0
在Javascript中文件的变化是这样的:
if(location.protocol === 'http:'){
var conn = new WebSocket('ws://192.168.43.31/ws');
}
else{
var conn = new WebSocket('wss://192.168.43.31/ws');
}
因此,apache 会将所有包含 ws 的请求重定向回 8080 端口