title: How to configure apache for use with asgi
body: <p>I have followed some the tutorial on setting up django channels and reading the docs on asgi as well, and been having difficulty, proxying my websocket requests to the necessary daphne listener.</p>
  
  <p>Here is what daphne shows:</p>
  
  <pre><code>$ $ daphne -v2 -b 127.0.0.1 -p 8443 asgi:application
  
  2018-10-07 03:48:33,533 INFO     Starting server at tcp:port=8443:interface=127.0.0.1
  2018-10-07 03:48:33,534 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
  2018-10-07 03:48:33,534 INFO     Configuring endpoint tcp:port=8443:interface=127.0.0.1
  </code></pre>
  
  <p>(Note: I've also tried the SSL version, with <code>$ daphne -e ssl:8444:privateKey=privkey.pem:certKey=fullchain.pem asgi:application -b 127.0.0.1 -p 8443
  </code></p>
  
  <p>And in my apache.conf file:</p>
  
  <pre><code>WSGIScriptAlias / home/david/data-py/wsgi.py
  WSGIPythonPath /home/david/lib/python3.6/site-packages
  
  RewriteEngine on
  RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
  RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
  RewriteRule .* wss://127.0.0.1:8443%{REQUEST_URI} [P,L]
  &lt;VirtualHost *:80&gt;
      ServerName d.data.com
      &lt;Directory /home/david/data-py&gt;
         Order allow,deny
         Allow from all
         Require all granted
      &lt;/Directory&gt;
      RewriteCond %{SERVER_NAME} =d.data.com
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>And finally, in the actual browser, I'm doing:</p>
  
  <pre><code>new WebSocket('wss://d.data.com/ws/registration/asdf1')
  # it was working on localhost at "wss://localhost:8000/ws/registration/02488"
  </code></pre>
  
  <p>And there are all enabled:</p>
  
  <ul>
  <li>a2enmod rewrite </li>
  <li>a2enmod proxy </li>
  <li>a2enmod proxy_wstunnel</li>
  </ul>
  
  <p>Am I missing something in the above configuration? Every time I go to the websocket page it just 404's so it's obviously not 'picking up' the ws request. Perhaps some of this is related to using https? There's nothing about that in the django-channels or asgi documentation that I could find.</p>
  
  <p>Finally, if this is any useful:</p>
  
  <pre><code>david@instance-3:~$ sudo netstat -ntlp | grep LISTEN
  tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      400/systemd-resolve 
  tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1010/sshd           
  tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      3713/mysqld         
  tcp6       0      0 :::80                   :::*                    LISTEN      14853/apache2       
  tcp6       0      0 :::22                   :::*                    LISTEN      1010/sshd           
  tcp6       0      0 :::443                  :::*                    LISTEN      14853/apache2      
  </code></pre>