Posted under » Apache » Django on 16 July 2026
Continue from part 1 and part 2.
To run ASGI server
$ uvicorn mywebsite.asgi:application $ uvicorn d52.asgi:application --host 192.168.1.17 --port 8050
As mentioned earlier, we are using Uvicorn as our ASGI or websockets server instead of Daphne and we are using Apache instead of NGNIX as a reverse proxy to Gunicon. It doesn't matter what you use, but take note of the port of your ASGI server which is never 80 which is your WSGI port.
As I am using Apache, my config is like this
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://192.168.1.17:8050%{REQUEST_URI} [P,QSA,L]
The directive RewriteCond %{HTTP:Upgrade} websocket is an Apache mod_rewrite condition used to intercept WebSocket handshake requests. It checks whether the incoming HTTP Upgrade header contains the value websocket, allowing the server to dynamically route WebSocket traffic differently than standard HTTP traffic.
The directive RewriteCond %{HTTP:CONNECTION} ^Upgrade$ is an Apache mod_rewrite rule condition used to check if an incoming HTTP request contains a Connection header with the exact value "Upgrade". It is most frequently used to detect WebSocket handshake requests so a reverse proxy can route them properly.
P - (Proxy) Forces the target to be handled by mod_proxy. It sends the request through an internal proxy rather than a standard rewrite.
QSA - (Query String Append) Combines and preserves any query parameters (like ?id=123) from the client's original request into the forwarded request.
L - (Last) Tells Apache to stop processing any subsequent rewrite rules in the configuration file for this matching request.
More on Rewrite.