Open
Description
Hi,
I would like to use ws4redis on Ubuntu 14.04
with Apache 2.4.7
. The version of uwsgi for Ubuntu 14.04 is 2.0.6, but do not seem to be compiled with websockets support, so I installed the version 2.0.11.2
with pip. I also edited /etc/init.d/uwsgi
so it launches the pip version.
I just want to load a Hello world
websocket page, and see the message in the browser console.
- It works with
manage.py runserver
- It works with a standalone uwsgi server running wsgi.py.
- It works with uwsgi behind nginx.
- It does not work with uwsgi behind apache. The socket is connected, but the browser never receive any message.
- It works with apache if I replace wsgi_websockets.py with the following python code.
import uwsgi
def application(env, start_response):
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
uwsgi.websocket_send("Hello world")
while True:
msg = uwsgi.websocket_recv()
uwsgi.websocket_send(msg)
foobar/views.py
def index(request):
pub = RedisPublisher(facility="hello", broadcast=True)
pub.publish_message(RedisMessage("Hello world"))
....
foobar/static/foobar.js
$(function() {
ws4redis = WS4Redis({
uri: WEBSOCKET_URI + 'hello?subscribe-broadcast&echo',
receive_message: wsReceive,
heartbeat_msg: WEBSOCKET_HEARTBEAT
});
});
The symptoms I get are:
- I think I need to te that I use this behind SSL, and it usually work fine. I also tested all this with regular http, and it has been the same.
- The browser console shows:
"Connecting to wss://foobar.com/ews/hello?subscribe-broadcast&echo ..." ws4redis.js:18:4
Connected! ws4redis.js:46:3
- If I manually reach https://foobar.com/ws/hello?subscribe-broadcast&echo, after a while I get a apache 500 error.
'HTTP_SEC_WEBSOCKET_KEY' Internal Server Error ....
but if I do this with uwsgi, I get this message:Client does not wish to upgrade to a websocket
. - uwsgi logs and apache error log do not seem to dump useful information
- My django log shows:
ERROR 2015-11-06 10:18:53,433 31152 wsgi_server:122 Other Exception: 'HTTP_SEC_WEBSOCKET_KEY'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ws4redis/wsgi_server.py", line 81, in __call__
websocket = self.upgrade_websocket(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/ws4redis/uwsgi_runserver.py", line 52, in upgrade_websocket
uwsgi.websocket_handshake(environ['HTTP_SEC_WEBSOCKET_KEY'], environ.get('HTTP_ORIGIN', ''))
KeyError: 'HTTP_SEC_WEBSOCKET_KEY'
/etc/apache2/sites-enabled/foobar.com.conf
<VirtualHost _default_:443>
<IfModule mod_proxy_wstunnel.c>
ProxyPass /ws/ ws://127.0.0.1:3032/
ProxyPassReverse /ws/ ws://127.0.0.1:3032/
</IfModule>
<IfModule mod_proxy_uwsgi.c>
ProxyPass /static !
ProxyPass /media !
ProxyPass / uwsgi://127.0.0.1:3031/
</IfModule>
</VirtualHost>
/etc/uwsgi/apps-enabled/websockets.ini
[uwsgi]
chdir = /path/to/foobar
module = foobar.wsgi_websockets:application
master = true
processes = 2
socket = /path/to/foobar/websockets.socket
http-socket = 127.0.0.1:3032
chmod-socket = 666
vacuum = true
env = DJANGO_SETTINGS_MODULE=foobar.settings
env = DJANGO_STATIC_ROOT=/path/to/foobar/static
gevent = 1000
http-websockets = true
Metadata
Metadata
Assignees
Labels
No labels