gpt4 book ai didi

apache - 如何在 https 中访问 websocket?

转载 作者:太空宇宙 更新时间:2023-11-03 14:36:56 24 4
gpt4 key购买 nike

完成以下配置以通过 SSL 连接 ws。

使用 Apache 2.4 服务器

在httpd.conf中

<VirtualHost *:8060>
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/BizMessenger/(.*) ws://xxx:8070/BizMessenger/$1 [P,L]
ProxyPass /BizMessenger ws://xxx:8070/BizMessenger/hello/chat
</VirtualHost>

错误:在请求操作期间浏览器中出现以下错误。

biz.js.xhtml?ln=js:49 Mixed Content: The page at 'https://xxx/main' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://xxx:8060/BizMessenger/hello/chat'. This request has been blocked; this endpoint must be available over WSS.send_message @ biz.js.xhtml?ln=js:49 biz.js.xhtml?ln=js:49 Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS. at send_message (https://xxx/javax.faces.resource/biz.js.xhtml?ln=js:49:17)
at init (https://xxx/javax.faces.resource/biz.js.xhtml?ln=js:44:5)
at autochatlogin (https://xxx/javax.faces.resource/svmchat.js.xhtml?ln=js:85:1)
at HTMLButtonElement.onclick (https://xxx/main:1201:283)

Chrome 在地址栏中抛出一个屏蔽以加载不安全的脚本

最佳答案

以下配置均在httpd-ssl.conf 下完成

 RewriteEngine On
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
# the description of below code
#RewriteRule webcontext ws://prpxy server ip:port(redirecting port in vhost)
RewriteRule ^/BizMessenger/(.*) ws://192.168.18.31:8060/BizMessenger/$1 [P,L]

V_host.conf 文件

<VirtualHost *:8060>
RewriteEngine On
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
# the description of below code
#RewriteRule webcontext ws://appserver ip:port
RewriteRule ^/BizMessenger/(.*) ws://192.168.18.50:8070/BizMessenger/$1 [P,L]
</VirtualHost>

websocket 连接请求:对于 SSL: wss://192.168.18.31/BizMessenger/hello/chat

关于apache - 如何在 https 中访问 websocket?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46902345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com