Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

323
Vistas
Apache websocket works with ProxyPass but not RewriteRule

I'm trying to enable websockets on an AWS ElasticBeanstalk Tomcat 8.5 web app. I have a custom apache config (abbreviated):

RewriteEngine On
RewriteOptions Inherit

ProxyRequests Off
ProxyPreserveHost on

# send websocket requests to tomcat with the websocket protocol
RewriteCond ${HTTP:Connection}  "Upgrade" [NC]
RewriteCond ${HTTP:Upgrade}     "websocket" [NC]
RewriteRule /(.*) "ws://localhost:8080/$1" [P,L]

# send all other requests to tomcat
ProxyPass           /   http://localhost:8080/  retry=0
ProxyPassReverse    /   http://localhost:8080/

In the web app, when I try to connect the client websocket to the server endpoint, I get this error:

websocket.js:372 WebSocket connection to 'wss://example.com/ws/sales' failed: Error during WebSocket handshake: Unexpected response code: 404

I verified in Chrome's developer tools that the Connection and Upgrade headers sent in the request to the above endpoint are correct. (Obviously I'm really connecting to my website, not example.com)

When I change the apache config to use ProxyPass instead of RewriteRule, it works perfectly! I don't want to do it this way because I don't want to proxy to ws simply based on the URI. I want to check the headers like you're supposed to!

ProxyRequests Off
ProxyPreserveHost on

# send websocket requests to tomcat with the websocket protocol
ProxyPass           /ws/    ws://localhost:8080/ws/ retry=0
ProxyPassReverse    /ws/    ws://localhost:8080/ws/

# send all other requests to tomcat
ProxyPass           /   http://localhost:8080/  retry=0
ProxyPassReverse    /   http://localhost:8080/
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I stumbled upon the solution to this simply by trial and error, which is to remove the L (last) flag from the RewriteRule. What I don't understand still is why that fixes it. I figured it would be good to post this answer anyway.

RewriteEngine On
RewriteOptions Inherit

ProxyRequests Off
ProxyPreserveHost on

# send websocket requests to tomcat with the websocket protocol
RewriteCond %{HTTP:Upgrade}     "websocket" [NC]
RewriteCond %{HTTP:Connection}  "Upgrade" [NC]
RewriteRule .* "ws://localhost:8080%{REQUEST_URI}" [P]

# send all other requests to tomcat
ProxyPass           /   http://localhost:8080/  retry=0
ProxyPassReverse    /   http://localhost:8080/
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda