【发布时间】:2022-01-09 14:32:23
【问题描述】:
我正在使用 Apache(httpd...Server version: Apache/2.4.37 (centos 8)) 在 Namecheap vps 上部署 Golang(go1.16.7) 后端
除了 websocket 连接之外,一切都有效。
请求:
wss://editor.xyzw.com/crownies/ws/upload/file?email=gbenroscience@gmail.com
当我尝试访问 websocket 连接时,它给出:
the client is not using the websocket protocol:'upgrade' token not found in 'Connection' header
(我在生产的 golang 代码中打印了这个错误)
websocket 在本地开发中工作,所以我知道 Golang 代码运行良好。 我确定问题出在我在 Apache 中的 vhost 配置中。
这是我的虚拟主机文件:
<VirtualHost *:443>
ServerName editor.xyzw.com
ServerAlias editor.xyzw.com www.editor.xyzw.com http://www.editor.xyzw.com
UseCanonicalName Off
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog /var/log/httpd/editor_access.log combined
ErrorLog /var/log/httpd/editor_error.log
DocumentRoot /path/to/my/document/root
SSLEngine on
SSLCertificateFile /opt/ssl/cert.crt
SSLCertificateKeyFile /opt/ssl/cert.key
SSLCACertificateFile /opt/ssl/cert.ca-bundle
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule ^/ws(.*) ws://localhost:8080/crownies/ws/$1 [P,L]
ProxyRequests off
<Location />
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
</VirtualHost>
来自 Google Chrome 的请求标头:
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cache-Control: no-cache
Connection: Upgrade
Cookie: user=blah-blah-blah
Host: editor.xyzw.com
Origin: https://editor.xyzw.com
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: blah-blah-blah==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36
请问我的虚拟主机有什么问题?
【问题讨论】:
标签: javascript apache websocket virtualhost