pythondjangowebsocketdjango-channelsdaphne

Django Channels on IIS using FASTCGI


I am deploying a Django app using an IIS server. In this Django app, I have implemented Django Channels to use websockets. Locally, everything is working fine with websocket connections, and I am able to send messages. However, the issue arises when I deploy the Django app. The HTTPS works perfectly fine, but the WSS (WebSocket Secure) is not working. I encounter a 404 not found error.

the url in which I am trying is

wss://my_domain/ws/start-quiz/

also note that i am using memurai instead of redis to use channel_layers

CHANNEL_LAYERS = {
        'default': {
            'BACKEND': 'channels_redis.core.RedisChannelLayer',
            'CONFIG': {
                "hosts": [('127.0.0.1', 6370)],
            },
        },
    }

Solution

  • I had same issue, I solved this using Daphne with channels. my web.config file conatins

    rules>
       <rule name="WebSocketProxy" stopProcessing="true">
         <match url="^ws/(.*)" />
            <action type="Rewrite" url="http://127.0.0.1:8001/ws/{R:1}" />
       </rule>
    </rules>
    

    and to run Daphne on local I used following command

    daphne -p 8000 your_project_name.asgi:application
    

    Please make sure first your Django project configuration using IIS with FASTCGI is correct