How to get Vaadin Push work through Apache HTTP server?

泪湿孤枕 提交于 2019-12-03 03:24:43

I solved this by making sure the path of ProxyPass (and ProxyPassReverse) is identical to the context of the application and creating a new NIO connector in tomcat's server.xml config:

<Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol"
           connectionTimeout="20000"
           redirectPort="8443"
           proxyName="mydomain"
           proxyPort="80" />

I'm quite sure there is a way to use a path that is different from the application context, but this works for me.

UPDATE: Note that this solution doesn't work with browsers that don't support websocket (eg. IE <= 9). I suspect it has something to do with the HTTP streaming as fallback method..

here is how you can do with two connectors: nio and ajp.

Tomcat config:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
    connectionTimeout="20000" />

<Connector port="8009" protocol="AJP/1.3" />

Apache config with mod_rewrite and mod_proxy (and mod_proxy_wstunnel enabled) :

RewriteEngine on
RewriteCond %{QUERY_STRING} ^((?!X-Atmosphere-Transport=websocket).)*$
RewriteRule ^/PUSH(.*)$ http://app.domain.com:8080/PUSH$1 [P]

ProxyPass /PUSH ws://app.domain.com:8080/PUSH
ProxyPassReverse /PUSH ws://app.domain.com:8080/PUSH

ProxyPass / ajp://localhost:8009/
  • First, every push request that does NOT have the X-Atmosphere-Transport=websocket parameter is sent to the nio connector with the http protocol. (So streaming fallback can happen)
  • Then, other push requests (websockets) are sent to the nio connector via mod_proxy_wstunnel.
  • Other requests (non push) are sent to the ajp connector.

I also ran into the this problem. The following snippet did the trick for me:

<Location /vaadinServlet/PUSH>
   Require all granted
   RewriteEngine on
   RewriteCond %{HTTP:UPGRADE} ^websocket$ [NC]
   RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
   RewriteRule .* ws://localhost:8080%{REQUEST_URI} [P]
</Location>

And you need mod_proxy_wstunnel.

I'm using Apache 2.4.10 and Vaadin 7.7.3 with Spring Boot 1.4.2 and Tomcat 8.5.6.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!