Websocket Apache 2.4.x 代理 Tomcat 7.x 打开事件只发生在浏览器端
Websocket Apache 2.4.x Proxy Tomcat 7.x open event happens only on browser side
我在浏览器端和服务器上使用 javascript 编写了一个聊天应用程序
用 javax.websocket api 编程的端点。我首先测试了应用程序
通过在浏览器和 tomcat 以及所有内容之间建立连接
工作正常(OS 是 Windows 7)。
当我尝试使用 apache 2.4.18 服务器作为 ssl 反向代理时,似乎连接没有完全建立,我只在浏览器上收到一个 onopen
事件。
我的 tomcat 日志告诉我,服务器端点实例也已创建,但 onopen
事件不会在服务器端点实例上发生。在我看来,服务器端点侦听了错误的端口或类似的东西。
我在 tomcat 端使用了一个 ajp 连接器。我试图解决问题或了解可能会失败的地方,但没有成功。
这是我的代码片段:
Chrome-网络日志:
Chrome-Javascript-控制台:
controller_chat.js:1952 chatBuildWSLink
controller_chat.js:1960 wsLink: wss://x:443/myapp/chat
controller_chat.js:343 chatCheckConnection
controller_chat.js:345 connect
controller_chat.js:313 Connecting to wss://x:443/myapp/chat
controller_chat.js:353 wsServerOnOpen
controller_chat.js:363 wsServerOnMessage
controller_chat.js:411 wsServerOnError
controller_chat.js:422 wsServerOnClose
controller_chat.js:228 chatCreateMenuBar
controller_chat.js:5 chatCreateTable
controller_chat.js:5 chatCreateTable
controller_chat.js:5 chatCreateTable
controller_chat.js:5 chatCreateTable
controller_chat.js:355 onopen Event: {"isTrusted":true}
controller_chat.js:356 onopen Event-Code: undefined
controller_chat.js:357 onopen Event-Reason: undefined
controller_chat.js:358 onopen Event-WasClean: undefined
我的 apache httpd-conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule ssl_module modules/mod_ssl.so
ProxyPass /myapp/chat/ wss://x:443/myapp/chat
ProxyPassReverse /myapp/chat/ wss://x:443/myapp/chat
ProxyPass /myapp/ ajp://x:8009/myapp/
ProxyPassReverse /eProjectCare/ ajp://x:8009/myapp/
NameVirtualHost myhost
<VirtualHost myhost:443>
...
DocumentRoot "c:/Apache24/htdocs"
ServerName myhost
ServerAdmin admin@example.com
SSLEngine on
SSLProxyEngine on
SSLCertificateFile "c:/OpenSSL-Win64/bin/chat.crt"
SSLCertificateKeyFile "c:/OpenSSL-Win64/bin/chat.key"
...
</VirtualHost>
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 1000
我的Tomcat-日志:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.checkOrigin , originHeaderValue: https://myhost
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.checkOrigin checkOrigin: true
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedSubprotocol , getNegotiatedSubprotocol:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedSubprotocol, negotiated Subprotocoll:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedExtensions , getNegotiatedExtensions:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedExtensions, negotiatedExtensions: permessage-deflate
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedExtensions NegotiatedExtensions: [org.apache.tomcat.websocket.WsExtension@28130514]
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , modifyHandshake:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , HttpSession: org.apache.catalina.session.StandardSessionFacade@3fbf9eec
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , csrfsession: 5e7f914546aef5bf389472c86b67234c1e68dc1e
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , csrfrequest:
09:39:50.758 [ajp-bio-8009-exec-2] DEBUG admin (3/1) SecurityService.readUser: Benutzer 3 wird aus der Datenbank gelesen ...
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) DatabaseService.closeConnection: schliesse Connection fuer: <.getLiveUser:> (1137989066)
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , userProperties for ServerEndpointConfig set...: {}
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getEndpointInstance , getEndpointInstance:
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer Erstelle Endpoint-Instanz!
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getEndpointInstance Endpoint-Instance: de.pmgnet.eprojectcare.websocket.chat.chatserver.ChatServer@3f39a0a
通常在那之后,onopen 事件发生在我的服务器 - endpoint.class 中并被记录下来,但这只有在我建立连接而不使用代理到 tomcat...[=19= 时才会发生]
这是我关于 Whosebug 的第一个问题,如果我在订阅中忘记了一些重要信息,请耐心等待。将
如果有人有建议,那就太好了。谢谢!
在您的代理设置中将 / 添加到 wss 的末尾
ProxyPass /myapp/chat/ wss://x:443/myapp/chat/
ProxyPassReverse /myapp/chat/ wss://x:443/myapp/chat/
对于所有可能为同一主题而苦恼的人,
经过大量浏览网站和阅读,我找到了解决方案,并将为所有感兴趣的人做出结论。
AJP-Connector:
AJP - connector of tomcat 7 does not! support websocket but it also
does not give any logs or errors, see also this:
1:
https://mail-archives.apache.org/mod_mbox/tomcat-users/201408.mbo
x/%3C53FF3A3A.3040507@christopherschultz.net%3E
所以对于 websocket,我使用了 https - 连接器,它已经随 apache server.xml tomcat:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="E:\ssl\mykeystore" keystorePass="315225" keyPass="315225"
clientAuth="false" sslProtocol="TLS" />
I defined a selfsigned certificate regarding to the article of bob: enter link description here
> httdp.conf
我更改了 httpd.conf 中的端口以适应 proxypass:
ProxyPass /myapp/chat wss://myhost:8443/myapp/chat
ProxyPassReverse /myapp/chat wss://myhost:8443/myapp/chat
ProxyPass /myapp/ https://myhost:8443/myapp/
ProxyPassReverse /myapp/ https://myhost:8443/myapp/
Well, this was ending in an Proxy-Error caused by the
self-signed-certificate of the tomcat. For testing and development you
can avoid this with a few additional rows in the httpd.conf:
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
</IfModule>
我要解决的最后一件事是在我的 pom.xml 中为 websocket 选择正确的依赖项,具体取决于 tomcat 版本,它可以在 maven-repository 上找到: enter link description here 应该是这样的:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>7.0.64</version>
</dependency>
Don't use the javax.websocket dependency, even with the
<scope>provided</scope>
attribute it didn't work for me (maybe i did
something wrong or forgot something)
Hope this works and helps you guys:-)
我在浏览器端和服务器上使用 javascript 编写了一个聊天应用程序 用 javax.websocket api 编程的端点。我首先测试了应用程序 通过在浏览器和 tomcat 以及所有内容之间建立连接 工作正常(OS 是 Windows 7)。
当我尝试使用 apache 2.4.18 服务器作为 ssl 反向代理时,似乎连接没有完全建立,我只在浏览器上收到一个 onopen
事件。
我的 tomcat 日志告诉我,服务器端点实例也已创建,但 onopen
事件不会在服务器端点实例上发生。在我看来,服务器端点侦听了错误的端口或类似的东西。
我在 tomcat 端使用了一个 ajp 连接器。我试图解决问题或了解可能会失败的地方,但没有成功。
这是我的代码片段:
Chrome-网络日志:
Chrome-Javascript-控制台:
controller_chat.js:1952 chatBuildWSLink
controller_chat.js:1960 wsLink: wss://x:443/myapp/chat
controller_chat.js:343 chatCheckConnection
controller_chat.js:345 connect
controller_chat.js:313 Connecting to wss://x:443/myapp/chat
controller_chat.js:353 wsServerOnOpen
controller_chat.js:363 wsServerOnMessage
controller_chat.js:411 wsServerOnError
controller_chat.js:422 wsServerOnClose
controller_chat.js:228 chatCreateMenuBar
controller_chat.js:5 chatCreateTable
controller_chat.js:5 chatCreateTable
controller_chat.js:5 chatCreateTable
controller_chat.js:5 chatCreateTable
controller_chat.js:355 onopen Event: {"isTrusted":true}
controller_chat.js:356 onopen Event-Code: undefined
controller_chat.js:357 onopen Event-Reason: undefined
controller_chat.js:358 onopen Event-WasClean: undefined
我的 apache httpd-conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule ssl_module modules/mod_ssl.so
ProxyPass /myapp/chat/ wss://x:443/myapp/chat
ProxyPassReverse /myapp/chat/ wss://x:443/myapp/chat
ProxyPass /myapp/ ajp://x:8009/myapp/
ProxyPassReverse /eProjectCare/ ajp://x:8009/myapp/
NameVirtualHost myhost
<VirtualHost myhost:443>
...
DocumentRoot "c:/Apache24/htdocs"
ServerName myhost
ServerAdmin admin@example.com
SSLEngine on
SSLProxyEngine on
SSLCertificateFile "c:/OpenSSL-Win64/bin/chat.crt"
SSLCertificateKeyFile "c:/OpenSSL-Win64/bin/chat.key"
...
</VirtualHost>
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 1000
我的Tomcat-日志:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.checkOrigin , originHeaderValue: https://myhost
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.checkOrigin checkOrigin: true
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedSubprotocol , getNegotiatedSubprotocol:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedSubprotocol, negotiated Subprotocoll:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedExtensions , getNegotiatedExtensions:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedExtensions, negotiatedExtensions: permessage-deflate
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getNegotiatedExtensions NegotiatedExtensions: [org.apache.tomcat.websocket.WsExtension@28130514]
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , modifyHandshake:
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , HttpSession: org.apache.catalina.session.StandardSessionFacade@3fbf9eec
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , csrfsession: 5e7f914546aef5bf389472c86b67234c1e68dc1e
09:39:50.756 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , csrfrequest:
09:39:50.758 [ajp-bio-8009-exec-2] DEBUG admin (3/1) SecurityService.readUser: Benutzer 3 wird aus der Datenbank gelesen ...
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) DatabaseService.closeConnection: schliesse Connection fuer: <.getLiveUser:> (1137989066)
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.modifyHandshake , userProperties for ServerEndpointConfig set...: {}
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getEndpointInstance , getEndpointInstance:
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer Erstelle Endpoint-Instanz!
09:39:50.759 [ajp-bio-8009-exec-2] DEBUG admin (3/1) ChatServer.getEndpointInstance Endpoint-Instance: de.pmgnet.eprojectcare.websocket.chat.chatserver.ChatServer@3f39a0a
通常在那之后,onopen 事件发生在我的服务器 - endpoint.class 中并被记录下来,但这只有在我建立连接而不使用代理到 tomcat...[=19= 时才会发生]
这是我关于 Whosebug 的第一个问题,如果我在订阅中忘记了一些重要信息,请耐心等待。将 如果有人有建议,那就太好了。谢谢!
在您的代理设置中将 / 添加到 wss 的末尾
ProxyPass /myapp/chat/ wss://x:443/myapp/chat/
ProxyPassReverse /myapp/chat/ wss://x:443/myapp/chat/
对于所有可能为同一主题而苦恼的人, 经过大量浏览网站和阅读,我找到了解决方案,并将为所有感兴趣的人做出结论。
AJP-Connector:
AJP - connector of tomcat 7 does not! support websocket but it also does not give any logs or errors, see also this: 1: https://mail-archives.apache.org/mod_mbox/tomcat-users/201408.mbo x/%3C53FF3A3A.3040507@christopherschultz.net%3E
所以对于 websocket,我使用了 https - 连接器,它已经随 apache server.xml tomcat:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="E:\ssl\mykeystore" keystorePass="315225" keyPass="315225"
clientAuth="false" sslProtocol="TLS" />
I defined a selfsigned certificate regarding to the article of bob: enter link description here
> httdp.conf
我更改了 httpd.conf 中的端口以适应 proxypass:
ProxyPass /myapp/chat wss://myhost:8443/myapp/chat
ProxyPassReverse /myapp/chat wss://myhost:8443/myapp/chat
ProxyPass /myapp/ https://myhost:8443/myapp/
ProxyPassReverse /myapp/ https://myhost:8443/myapp/
Well, this was ending in an Proxy-Error caused by the self-signed-certificate of the tomcat. For testing and development you can avoid this with a few additional rows in the httpd.conf:
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
</IfModule>
我要解决的最后一件事是在我的 pom.xml 中为 websocket 选择正确的依赖项,具体取决于 tomcat 版本,它可以在 maven-repository 上找到: enter link description here 应该是这样的:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>7.0.64</version>
</dependency>
Don't use the javax.websocket dependency, even with the
<scope>provided</scope>
attribute it didn't work for me (maybe i did something wrong or forgot something)Hope this works and helps you guys:-)