Search code examples
djangowebsocketapache2django-channelschannel

Different websocket endpoints with Apache2 vs "manage.py runserver". Django Channels


I have different endpoints when i run Django in apache compare to when I run it in the terminal.

Can it be some configuration in apache?

I belive it can be this ? Apache 2 conf ProxyPass "/ws/" "ws://127.0.0.1:8000/"

What does this mean; "/ws/"?

Apache to work: ws_urlpatterns = [path('some_url/', Andring.as_asgi()), ]

Run in terminal: ws_urlpatterns = [path('ws/some_url/', Andring.as_asgi()), ]

In JS: const socket = new WebSocket("ws://" + window.location.host + "/ws/some_url/");


Solution

  • https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

    The examples below are only a very basic idea to help you get started. Please read the documentation on the individual directives.

    In addition, if you wish to have caching enabled, consult the documentation from mod_cache.

    ProxyPass "/foo" "http://foo.example.com/bar"
    ProxyPassReverse "/foo" "http://foo.example.com/bar"
    # Forward Proxy
    ProxyRequests On
    ProxyVia On
    
    <Proxy "*">
      Require host internal.example.com
    </Proxy>
    # Websocket Upgrade (2.4.47 and later)
    ProxyPass "/some/ws/capable/path/" "http://example.com/some/ws/capable/path/" upgrade=websocket