I have an apache proxy for meteor applications, and apache and meteor on two separate machines. I need this, since apache has to serve many real websites, and it would be nice to install a meteor application on this computer due to its limited resources.
However, WebSocket handshaking does not work with a 400 response code "Can only be updated on websocket" if I try to connect from the outside through a proxy. Everything works fine when I connect from the local network directly to the meteor machine. When the WebSocket is down, SockJS / Meteor returns to XHR, but unfortunately this causes some errors in the application in question. So I really need WebSocket to work in most cases.
I installed a fix for my apache installation with the patch mentioned here: https://stackoverflow.com/a/2206772/2326322: It all went well, but nothing changed ...
My apache proxy directives are currently as follows:
ProxyRequests Off ProxyPreserveHost On ModPagespeed Off <proxy> Order deny,allow Allow from all </proxy> ProxyPass / http://10.0.2.6:3000/ ProxyPassReverse / http://10.0.2.6:3000/
And I even know what causes the problem. Apache proxy works with header. The original request header of the package in question leaving my machine is as follows:
GET /sockjs/430/minw4r_o/websocket HTTP/1.1 Upgrade: websocket Connection: Upgrade Host: example.com Origin: http://example.com Pragma: no-cache Cache-Control: no-cache Sec-WebSocket-Key: myKey Sec-WebSocket-Version: 13 Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits, x-webkit-deflate-frame User-Agent: My Agent
So far, the packet is being forwarded from the apache proxy as follows:
GET /sockjs/430/minw4r_o/websocket HTTP/1.1 Host: example.com Origin: http://example.com Pragma: no-cache Cache-Control: no-cache Sec-WebSocket-Key: myKey Sec-WebSocket-Version: 13 Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits, x-webkit-deflate-frame User-Agent: My Agent X-Forwarded-For: 24.xxx.xxx.xxx X-Forwarded-Host: example.com X-Forwarded-Server: example.com Connection: Keep-Alive
So, the “Update” is deleted, and the “Connection” is changed, and therefore, handshaking with websocket is not performed. Now I could always put "Upgrade" in the "websocket" using the RequestHeader directive. However, this is not so, and I assume that it will cause other problems, and therefore I was wondering if there is a real solution to this problem? Or is this a patch from https://stackoverflow.com/a/2129608/2121/2121321_01.h needs to be addressed, and something went wrong on my part, applying it?
From what I read, switching to nginx could make this setup easier. I will consider this, but whenever possible, I would like to do it with apache, since nginx would complicate other things and cost me a lot of time.