我正在尝试使用 html 5 websockets 连接到我的 websocket 服务器。直接连接工作正常,但当我尝试将服务器隐藏在 apache 代理后面时,它不起作用。
结果是:
var ws = new WebSocket("wss://www.example.com/generator/wss/");
undefined
WebSocket connection to 'wss://www.example.com/generator/wss/' failed: Error during WebSocket handshake: Invalid status line
但如果我直接连接到 wss://www.example.com:9002 那么它就可以工作......
这是我的 Apache 配置:
<VirtualHost *:80>
ServerName www.example.com
ServerAdmin [email protected]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAdmin [email protected]
SetEnv EXAMPLE_SERVER_ENVIROMENT production
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"
SSLCertificateFile /etc/ssl/certs/apache/www.example.crt
SSLCertificateKeyFile /etc/ssl/certs/apache/private.key
SSLCertificateChainFile /etc/ssl/certs/apache/sub.class1.server.sha2.ca.pem
ProxyPass /generator/wss wss://127.0.0.1:9002/
ProxyPassReverse /generator/wss wss://127.0.0.1:9002/
ProxyPreserveHost On
ProxyRequests Off
ProxyVia On
DocumentRoot /opt/example/prod/public
<Directory "/opt/example/prod/public">
Order allow,deny
AllowOverride All
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
知道为什么它不起作用吗?谢谢
答案1
嗯,所以我不知道错误到底在哪里,但是当我将 apache2 从 2.4.7 升级到 2.4.16 时它就可以正常工作了......