我已经按照一些有关设置django频道和阅读有关asgi的文档的教程进行了学习,并且遇到了困难,无法将我的websocket请求代理到必要的daphne侦听器。
这里是达芙妮显示的内容:
$ $ 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
(注意:我也尝试过使用$ daphne -e ssl:8444:privateKey=privkey.pem:certKey=fullchain.pem asgi:application -b 127.0.0.1 -p 8443
在我的apache.conf文件中:
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]
<VirtualHost *:80>
ServerName d.data.com
<Directory /home/david/data-py>
Order allow,deny
Allow from all
Require all granted
</Directory>
RewriteCond %{SERVER_NAME} =d.data.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
最后,在实际的浏览器中,我正在做
new WebSocket('wss://d.data.com/ws/registration/asdf1')
# it was working on localhost at "wss://localhost:8000/ws/registration/02488"
所有功能均已启用:
我在上述配置中缺少什么吗?每次我进入websocket页面时,它都只是404,因此显然不是在“拿起” ws请求。也许其中一些与使用https有关?我在django-channels或asgi文档中没有找到关于这一点的信息。
最后,如果有用的话:
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