2

I'm trying to figure out how to properly setup apache redirect rules for back-end CherryPy server which implements websocket (done via ws4py module). The problem is that if you use rewrite engine or proxypass it strips off Upgrade header in redirected request and therefore CherryPy server complaints about it and fails at handshake step.

The scenario I have is the following. I have CherryPy server with ws4py module which setup WebSockets. It runs on localhost:9000. I want to have apache front-end which just redirect incoming request to back-end server (it does more than that, but for simplicity it should do just that).

The apache rule I have is simple

RewriteRule ^(/websocket(/.*)?)$ http://some_host:9000$1 [P,L]

so for all requests starting with /websocket it redirects them to back-end server running on port 9000. The P flag stands for Proxy, the L stops rewriting process (see http://borkweb.com/story/apache-rewrite-cheatsheet)

If client sends request with HTTP header Upgrade:websocket the apache engine (rewrite module) strips it off, which causes WebSocket handshake fails.

Is there are any way to fix rewrite rule to allow presence of Upgrade header?

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
Valentin
  • 1,492
  • 3
  • 18
  • 27
  • you say redirect, but you're really proxying. Since it's proxied, Upgrade: websocket being passed along would mean Apache is expecting to talk websockets to the backend system, which it's not prepared to do – covener Aug 22 '12 at 01:45

1 Answers1

2

Unfortunately, Apache doesn't have the capability to reverse proxy WebSocket connections yet (it absolutely should!). But there is a solution that allows web requests to be handled using Apache and WebSocket connections to be handled by something else. This solution involves using HAProxy as the front end to both apache and your WebSocket server.

Here are a couple of relevant links to get you started:

Community
  • 1
  • 1
kanaka
  • 70,845
  • 23
  • 144
  • 140