I've been trying unsuccessfully for a few days to setup a reverse proxy to a localhost websocket url.
ProxyPass /chat/stream/ wss://localhost:8000/chat/stream/
ProxyPassReverse /chat/stream/ wss://localhost:8000/chat/stream/
I get an error in the apache error_log that reads:
No protocol handler was valid for the URL /chat/stream/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
I have read countless pages via google of people using this method so I wonder if there is some issue in our setup/install of Apache that ships with Server.app 5.2?
I have all the standard modules loaded in httpd_server_app.conf
mod_proxy mod_proxy_wstunnel mod_proxy_http ...
Can anyone shed some light on this?
Thanks
Adam
In case someone finds themselves in a similar situation here is how I got WebSocket connections working via Apache in MacOS Server 5.2. And the solution is simple.
The short version:
I use MacOS Server 5.2 (ships with Apache 2.4.23) to run a python Django application via the
mod_wsgimodule.I had been trying to setup
proxypassandwstunnel in MacOS 10.12 & Server 5.2 to handle websocket connections via an ASGI interface server called Daphne running onlocalhoston port8001.I wanted to reverse proxy any WebSocket connection to
wss://myapp.local/chat/stream/tows://localhost:8001/chat/stream/From what I had read on all the forums and mailing lists that I had scoured was to simply make some
proxypassdefinitions in the appropriate virtual host and make sure that themod_proxyandmod_proxy_wstunnelmodules were loaded and it would work.Long story short - from what I understand all of this trouble came down to MacOS Server 5 and one major change:
All I needed to do to proxy the websocket connection was the following:
in:
/Library/Server/Web/Config/Proxy/apache_serviceproxy.confAdd (around
line 297(in the section about user websites, webdav):I then kicked over the service proxy:
And the web socket connections were instantly working!
The long version:
For many weeks I have been trying to get WebSocket connections functioning with Apache and Andrew Godwin's Django Channels project in an app I am developing.
Django Channels is
My interest in Django Channels came from my requirement of a chat system in my webapp. After watching a several of Andrew's demos on youtube and having read through the docs and eventually installing Andrew's demo django channels project I figured I would be able to get this working in production on our MacOS Server.
The current release of MacOS 10.12 and Server 5.2 ships with Apache 2.4.23. This comes with the necessary mod_proxy_wstunnel module to be able to proxy WebSocket connections (
ws://and securewss://) in Apache and is already loaded in the server config file:Daphne is Andrew's ASGI interface server that supports WebSockets & long-poll HTTP requests. WSGI does not.
With Daphne running on localhost on a port that MacOS isn't occupying (I went with
8001), the idea was to get Apache to reverse proxy certain requests to Daphne.Daphne can be run on a specified port (
8001in this example) like so (-v2for more verbosity):I wanted Daphne to handle only the web socket connections (as I use currently depend on some apache modules for serving media such as
mod_xsendfile). In my case thewebsocketconnection was via/chat/stream/based on Andrew's demo project.From what I had read in MacOS Server's implementation of Apache the idea is to declare these proxypass commands inside the virtual host files of your "sites" in:
/Library/Server/Web/Config/apache2/sites/In config files such as:
0000_127.0.0.1_34543_.confI did also read that any customisation for web apps running on MacOS Server should be made to the plist file for the required web app in:
/Library/Server/Web/Config/apache2/webapps/In a plist file such as:
com.apple.webapp.wsgi.plistAnyway...
I edited the
0000_127.0.0.1_34543_.conffile adding:Eager to test out my first web socket chat connection I refreshed the page only to see an error printed in the apache log:
I had read of many people finding a solution at least with Apache on Ubuntu or a custom install on MacOS. I even tried installing Apache using Brew and when that didn't work I almost proceeded to install
nginx.After countless hours/days of googling I reached to the Apache mailing list for some help with this error. Yann Ylavic was very generous with his time and offered me various ideas on how to get it going. After trying the following:
I noticed that the interface server on port 8001 Daphne was starting to receive ws connections! However in the client browser it was logging:
From what I could see
mod_dumpiowas logging that the"Connection: Upgrade"and"Upgrade: WebSocket"headers were being sent as part of the web socket handshake:However the client browser showed nothing in the response headers.
I was more stumped than ever.
I explored the client side jQuery framework as well as the the Django channels & autobahn module to see if perhaps something was amiss, and then revised my own app and various combinations of suggestions about Apache and it's module. But nothing stood out to me.
Then I reread the ReadMe.txt inside the apache2 dir:
/Library/Server/Web/Config/apache2/ReadMe.txtI wondered if thus ServiceProxy had something to do with it. I had a look over:
/Library/Server/Web/Config/Proxy/apache_serviceproxy.confand noticed a comment -"# The user websites, and webdav".I figured it wouldn't hurt to try adding the
proxypassdefinitions &rewriterules that people had suggested on the forums as their solution.Sure enough after restarting the
ServiceProxyit all started to work!Adam