首页 > 解决方案 > 为 Apache 服务器上的安全 WebSocket(wss) 连接部署 Django 通道

问题描述

在为 Apache 配置 Windows 服务器机器中的安全 WebSocket 连接时需要帮助。

请检查以下.conf文件,

httpd-vhost.conf:

Listen 8080
WSGIPythonPath "D:/django_project/"
<VirtualHost 10.66.88.87:8080>

    ServerName test.company.com
    ServerAlias test.company.com
    ServerAdmin xxxx.xxxx@company.com
    SSLEngine on
    SSLCertificateFile "D:/django_project/cert/certificate.cert"
    SSLCertificateKeyFile "D:/django_project/cert/privatekey.key"

    WSGIScriptAlias / "D:/django_project/django_project/wsgi.py"
    DocumentRoot "D:/django_project/"

    <Directory "D:/django_project/">
      <Files wsgi.py>
         AllowOverride All
         Require all granted
      </Files>
    </Directory>

    <Directory "D:/django_project/app/static">
        Require all granted
    </Directory>
    Alias /static "D:/django_project/app/static"

    ProxyRequests Off 
    ProxyPass /wss/  ws://10.66.88.87:8080   

    ErrorLog "D:/django_project/log/error.log"
    CustomLog "D:/django_project/log/access.log" common
</VirtualHost>

httpd-ssl.conf:

<VirtualHost _default_:443>

#   General setup for the virtual host
DocumentRoot "${SRVROOT}/htdocs"
ServerName www.example.com:443
ServerAdmin admin@example.com
ErrorLog "${SRVROOT}/logs/error.log"
TransferLog "${SRVROOT}/logs/access.log"

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on
....
....
.... # this file don't have changes

阿帕奇错误日志:

[Sat Nov 09 14:45:04.654465 2019] [mpm_winnt:notice] [pid 145260:tid 712] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sat Nov 09 14:45:06.686147 2019] [mpm_winnt:notice] [pid 117948:tid 660] AH00364: Child: All worker threads have exited.
[Sat Nov 09 14:45:07.938036 2019] [mpm_winnt:notice] [pid 145260:tid 712] AH00430: Parent: Child process 117948 exited successfully.
[Sat Nov 09 14:45:10.563900 2019] [ssl:warn] [pid 147168:tid 708] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:45:10.715008 2019] [ssl:warn] [pid 147168:tid 708] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:45:10.718010 2019] [mpm_winnt:notice] [pid 147168:tid 708] AH00455: Apache/2.4.39 (Win64) OpenSSL/1.1.1b mod_wsgi/4.5.24 Python/3.6 configured -- resuming normal operations
[Sat Nov 09 14:45:10.719011 2019] [mpm_winnt:notice] [pid 147168:tid 708] AH00456: Apache Lounge VC15 Server built: Mar 28 2019 11:59:33
[Sat Nov 09 14:45:10.719011 2019] [core:notice] [pid 147168:tid 708] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Sat Nov 09 14:45:10.843098 2019] [mpm_winnt:notice] [pid 147168:tid 708] AH00418: Parent: Created child process 48800
[Sat Nov 09 14:45:12.442235 2019] [ssl:warn] [pid 48800:tid 648] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:45:12.702419 2019] [ssl:warn] [pid 48800:tid 648] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:45:13.076684 2019] [mpm_winnt:notice] [pid 48800:tid 648] AH00354: Child: Starting 64 worker threads.
[Sat Nov 09 14:48:25.784540 2019] [mpm_winnt:notice] [pid 147168:tid 708] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sat Nov 09 14:48:55.829806 2019] [mpm_winnt:notice] [pid 147168:tid 708] AH00431: Parent: Forcing termination of child process 48800
[Sat Nov 09 14:49:00.749300 2019] [ssl:warn] [pid 121264:tid 704] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:03.883524 2019] [ssl:warn] [pid 121264:tid 704] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:03.887527 2019] [mpm_winnt:notice] [pid 121264:tid 704] AH00455: Apache/2.4.39 (Win64) OpenSSL/1.1.1b mod_wsgi/4.5.24 Python/3.6 configured -- resuming normal operations
[Sat Nov 09 14:49:03.887527 2019] [mpm_winnt:notice] [pid 121264:tid 704] AH00456: Apache Lounge VC15 Server built: Mar 28 2019 11:59:33
[Sat Nov 09 14:49:03.887527 2019] [core:notice] [pid 121264:tid 704] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Sat Nov 09 14:49:04.016619 2019] [mpm_winnt:notice] [pid 121264:tid 704] AH00418: Parent: Created child process 86184
[Sat Nov 09 14:49:05.008324 2019] [ssl:warn] [pid 86184:tid 656] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:05.110395 2019] [ssl:warn] [pid 86184:tid 656] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:05.230480 2019] [mpm_winnt:notice] [pid 86184:tid 656] AH00354: Child: Starting 64 worker threads.

项目错误日志:

[Sat Nov 09 14:49:00.752302 2019] [ssl:warn] [pid 121264:tid 704] AH01906: test.company.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sat Nov 09 14:49:00.752302 2019] [ssl:warn] [pid 121264:tid 704] AH01909: test.company.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:03.886526 2019] [ssl:warn] [pid 121264:tid 704] AH01906: test.company.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sat Nov 09 14:49:03.886526 2019] [ssl:warn] [pid 121264:tid 704] AH01909: test.company.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:05.012326 2019] [ssl:warn] [pid 86184:tid 656] AH01906: test.company.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sat Nov 09 14:49:05.012326 2019] [ssl:warn] [pid 86184:tid 656] AH01909: test.company.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:05.113398 2019] [ssl:warn] [pid 86184:tid 656] AH01906: test.company.com:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Sat Nov 09 14:49:05.113398 2019] [ssl:warn] [pid 86184:tid 656] AH01909: test.company.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 14:49:09.297369 2019] [wsgi:error] [pid 86184:tid 1308] [client 10.66.88.87:59493]  262steja6x8ru2lxd3xs6q1v9i4pjm8\r, referer: https://10.66.88.87:8080/

浏览器中的错误(chrome):

(索引):194 WebSocket 连接到“wss://10.66.88.87:8080/ws/home/”失败:WebSocket 握手期间出错:意外响应代码:404

高度赞赏任何类型的提示/建议(甚至包含此主题的链接)进行调试。

标签: pythonapachesslwebsocketwss

解决方案


推荐阅读