Apache 服务器:通过 mod_proxy_wstunnel 实现反向代理和 websockets

Apache 服务器:通过 mod_proxy_wstunnel 实现反向代理和 websockets

我的 Web 套接字和反向代理 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)

谢谢。

答案1

路径后面必须添加斜杠,因为必须将 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

相关内容