WebFaction
Community site: login faq

i have a Django project/website that hold 3 chatting application two of them is using HTTp request as a chatbot the uses views.py to retrieve the replay from the DataBase , and the third on is using Django channels and websockets as a normal basic one-to0one chatting app, connecting and echoing the messages worked perfectly but the problem is that when i try to send a message using Group() function in consumer.py it doesn't work.

So, i found out that the reason is that my websocket app doesn't seem to route correctly when running alongside my mod_wsgi app. So, the only solution is stopping my Apache,and then serving the whole app from your websockets port via the runserver command. When i did this the Group () worked, but the problem is i developed the whole website using Apache which it serves 2 of 3 apps in my Django website, the 3th one is using web sockets(and it took me a long time). I need both Apache and websockets in my Django project.

this is my Apache config:

  ServerRoot "/home/mansard/webapps/gadgetron/apache2"

    LoadModule authz_core_module modules/mod_authz_core.so
    LoadModule dir_module        modules/mod_dir.so
    LoadModule env_module        modules/mod_env.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule mime_module       modules/mod_mime.so
    LoadModule rewrite_module    modules/mod_rewrite.so
    LoadModule setenvif_module   modules/mod_setenvif.so
    LoadModule wsgi_module       modules/mod_wsgi.so
    LoadModule unixd_module      modules/mod_unixd.so
    LoadModule expires_module    modules/mod_expires.so


    LoadModule headers_module modules/mod_headers.so

    LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    CustomLog /home/mansard/logs/user/access_gadgetron.log combined
    ErrorLog /home/mansard/logs/user/error_gadgetron.log




    Listen 16709
    KeepAlive Off
    SetEnvIf X-Forwarded-SSL on HTTPS=1
    ServerLimit 1
    StartServers 1
    MaxRequestWorkers 5
    MinSpareThreads 1
    MaxSpareThreads 3
    ThreadsPerChild 5





    Header set Access-Control-Allow-Origin: *

    Header set Access-Control-Allow-Headers: content-type

    Header set Access-Control-Allow-Methods: *


    WSGIDaemonProcess gadgetron processes=2 threads=12 python-path=/home/mansard/webapps/gadgetron:/home/mansard/webapps/gadgetron/src:/home/mansard/webapps/gadgetron/lib/python3.5
    WSGIProcessGroup gadgetron
    WSGIRestrictEmbedded On
    WSGILazyInitialization On
    WSGIScriptAlias  / /home/mansard/webapps/gadgetron/src/chatbot/wsgi.py process-group=gadgetron application-group=%{GLOBAL}

Any ideas how to address this issue?

PS: someone told me that i need to switch to Nginx as my website configuration (How i can accomplish that?)

asked 12 Sep, 18:17

eman_saad's gravatar image

eman_saad
112
accept rate: 0%

edited 12 Sep, 18:19


In a perfect world, the solution would be to configure your website as follows:

  • / serving your mod_wsgi application
  • /some_path serving your websockets application, with the Django daphne server listening on your websockets app assigned port, and using the "root-path" parameter to tell daphne that it's running on a subpath, like: daphne --root-path=/some_path -p 12345 myproject.asgi:channel_layer

However, this doesn't work. What happens is that daphne sees the requests coming in on / instead of /some_path, and as a result the websockets requests are not routed correctly.

I reached out to the daphne developer for a solution, and he informed me that the problem is related to this bug: Daphne-Root-Path not taken in consideration in consumers URLs. He said it might be possible to work around the issue by "coding all URLs as absolute and making nginx pass them through as such", but unfortunately on our setup you can't configure the front-end Nginx server in this manner.

So, until the bug in Daphne is fixed, my advise is that if you need to run a Django project that uses Channels, you should either:

  • a) Forego the use of mod_wsgi, and serve the entire site from daphne. This way, daphne will be running from the root URL / and won't have any confusion about the routing for your websockets, or...
  • b) Serve your websockets from a separate site on a different subdomain, again serving daphne from the root URL /.
permanent link

answered 27 Sep, 00:58

seanf's gravatar image

seanf ♦♦
11.9k21333
accept rate: 37%

edited 27 Sep, 00:59

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×891
×27

question asked: 12 Sep, 18:17

question was seen: 250 times

last updated: 27 Sep, 00:59

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2017 PARAGON INTERNET GROUP LIMITED
WEBFACTION IS A SERVICE OF PARAGON INTERNET GROUP LIMITED
REGISTERED IN ENGLAND AND WALES 7573953 - VAT REGISTRATION NUMBER 182147021
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM