Apache-2.2

Apache 伺服器:通過 mod_proxy_wstunnel 反向代理和 websockets

  • November 12, 2013

我的 web sockets 和我的反向代理 apache 有一點問題,我已經升級到最新版本 2.4.5 並載入了模組 mod_proxy_wstunnel。

httpd.conf :

    <VirtualHost *:80> 
ServerAdmin webmaster@localhost 
ServerName www.toto.fr 
ServerAlias toto.fr


   ProxyPass /my_app  http://1X.X.X.1:8080/my_app 
   ProxyPassReverse /web_pmr  http://1X.X.X.1:8080/my_app 
   ProxyPassReverseCookiePath /my_app / 
   ProxyPassReverseCookieDomain localhost my_app 
   ProxyRequests off 
   ProxyTimeout 15

       #WEBSOCKETS


       ProxyPass /my_app/BasicWebsocketServlet ws://1X.X.X.1:8080/my_app/BasicWebsocketServlet retry=0 
   ProxyPassReverse /my_app/BasicWebsocketServlet ws://1X.X.X.1:8080/web_pmr/BasicWebsocketServlet retry=0


ErrorLog "logs/my_app_error.log" 
LogLevel debug 
CustomLog "logs/my_app_access.log" combined 

<Proxy *>
             Order deny,allow
             Allow from all 
</Proxy> 
</VirtualHost>

當我在我的本地 url 中測試時,websockets 正在工作,但使用反向代理 apache 在 tomcat 日誌中沒有任何痕跡。

載入模組列表:

Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) proxy_module (shared) proxy_connect_module (shared) proxy_ftp_module (shared) proxy_http_module (shared) proxy_fcgi_module (shared) proxy_scgi_module (shared) proxy_fdpass_module (shared) proxy_wstunnel_module (shared) proxy_ajp_module (shared) proxy_balancer_module (shared) proxy_express_module (shared) slotmem_shm_module (shared) slotmem_plain_module (shared) ssl_module (shared) lbmethod_byrequests_module (shared) lbmethod_bytraffic_module (shared) lbmethod_bybusyness_module (shared) lbmethod_heartbeat_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) rewrite_module (shared)

謝謝你。

必須在路徑中添加斜杠,必須將 Web 套接字請求作為 GET 請求處理(httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass

就像是:

ProxyPass        /my_app/BasicWebsocketServlet/ ws://1X.X.X.1:8080/my_app/BasicWebsocketServlet/ retry=0
ProxyPassReverse /my_app/BasicWebsocketServlet/ ws://1X.X.X.1:8080/web_pmr/BasicWebsocketServlet/ retry=0

引用自:https://serverfault.com/questions/523345