jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
895 stars 222 forks source link

Nginx websocket connection error (502) #71

Closed YuriHeupa closed 9 years ago

YuriHeupa commented 9 years ago

As described in http://django-websocket-redis.readthedocs.org/en/latest/running.html#django-with-websockets-for-redis-behind-nginx-using-uwsgi i've configured the server as the follows:

location / { include /etc/nginx/uwsgi_params; uwsgi_pass unix:/run/uwsgi/app/rtydev.com.br/socket; }

location /ws/ { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://unix:/run/uwsgi/app/rtydev.com.br/web.socket; }

When i try connecting to rtydev.com.br/ws/ i get the following error: GET http://rtydev.com.br/ws/ 502 (Bad Gateway)

What should be the right way for starting websocket uwsgi app ?

I'm using the following command: uwsgi --virtualenv /var/www/.virtualenvs/rtydev.com.br --http-socket /run/uwsgi/app/rtydev.com.br/web.socket --gevent 1000 --http-websockets --workers=2 --master --wsgi-file /srv/rtydev.com.br/www/ws-project-tracker/src/wsgi_websocket.py --env DJANGO_SETTINGS_MODULE=settings.global --chdir /srv/rtydev.com.br/www/ws-project-tracker/src

* Starting uWSGI 2.0.7 (64bit) on [Wed Jan 7 18:29:15 2015] compiled with version: 4.6.3 on 11 September 2014 14:37:08 os: Linux-3.16.5-x86_64-linode46 #1 SMP Mon Oct 13 09:42:16 EDT 2014 nodename: mercury machine: x86_64 clock source: unix detected number of CPU cores: 1 current working directory: /etc/uwsgi/apps-enabled detected binary path: /usr/local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! uWSGI running as root, you can use --uid/--gid/--chroot options \ WARNING: you are running uWSGI as root !!! (use the --uid flag) * your processes number limit is 3947 your memory page size is 4096 bytes detected max file descriptor number: 1024 async cores set to 1000 - fd table size: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to UNIX address /run/uwsgi/app/rtydev.com.br/web.socket fd 3 Python version: 2.7.3 (default, Feb 27 2014, 20:09:21) [GCC 4.6.3] Set PythonHome to /var/www/.virtualenvs/rtydev.com.br Python main interpreter initialized at 0x17da070 python threads support enabled your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 31099392 bytes (30370 KB) for 2000 cores * Operational MODE: preforking+async * WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x17da070 pid: 8050 (default app) * uWSGI is running in multiple interpreter mode * spawned uWSGI master process (pid: 8050) spawned uWSGI worker 1 (pid: 8055, cores: 1000) spawned uWSGI worker 2 (pid: 8056, cores: 1000) * running gevent loop engine [addr:0x489d50] *

Is this a bug?

jrief commented 9 years ago

Have a look into your nginx logs. Assumingly nginx is unable to communicate over that socket with uwsgi.

No, this for sure isn't a bug. This app has been deployed many hundreds of times and works perfectly.

YuriHeupa commented 9 years ago

* Starting uWSGI 2.0.7 (64bit) on [Wed Jan 7 20:36:07 2015] * Wed Jan 7 20:36:07 2015 - compiled with version: 4.6.3 on 11 September 2014 14:37:08 Wed Jan 7 20:36:07 2015 - os: Linux-3.16.5-x86_64-linode46 #1 SMP Mon Oct 13 09:42:16 EDT 2014 Wed Jan 7 20:36:07 2015 - nodename: mercury Wed Jan 7 20:36:07 2015 - machine: x86_64 Wed Jan 7 20:36:07 2015 - clock source: unix Wed Jan 7 20:36:07 2015 - detected number of CPU cores: 1 Wed Jan 7 20:36:07 2015 - current working directory: / Wed Jan 7 20:36:07 2015 - writing pidfile to /run/uwsgi/app/rtydev.com.br/pid Wed Jan 7 20:36:07 2015 - detected binary path: /usr/local/bin/uwsgi Wed Jan 7 20:36:07 2015 - !!! no internal routing support, rebuild with pcre support !!! Wed Jan 7 20:36:07 2015 - setgid() to 33 Wed Jan 7 20:36:07 2015 - set additional group 999 (www-users) Wed Jan 7 20:36:07 2015 - setuid() to 33 Wed Jan 7 20:36:07 2015 - your processes number limit is 3947 Wed Jan 7 20:36:07 2015 - your memory page size is 4096 bytes Wed Jan 7 20:36:07 2015 - detected max file descriptor number: 1024 Wed Jan 7 20:36:07 2015 - lock engine: pthread robust mutexes Wed Jan 7 20:36:07 2015 - thunder lock: disabled (you can enable it with --thunder-lock) Wed Jan 7 20:36:07 2015 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/rtydev.com.br/socket fd 3 Wed Jan 7 20:36:07 2015 - bind(): Permission denied [core/socket.c line 759] Wed Jan 7 20:36:07 2015 - * starting uWSGI Emperor *

Genarito commented 4 years ago

Perhaps It's not the case. But I was getting a 502 Gateway error because I was connecting to an url with a dot in it. Example: ws/users/gena.rito