【问题标题】:Enabling HTTP/2 Support in daphne with django使用 django 在 daphne 中启用 HTTP/2 支持
【发布时间】:2022-01-07 14:02:08
【问题描述】:

当我运行这个命令时

command: daphne -e ssl:443:privateKey=key.pem:certKey=crt.pem server.asgi:application --port 8000 --bind 0.0.0.0

我得到的错误如下

在 ssl:443:privateKey=key.pem:certKey=crt.pem 处启动服务器, tcp:port=8000:interface=0.0.0.0 HTTP/2 支持已启用 配置 端点 ssl:443:privateKey=key.pem:certKey=crt.pem Traceback(大多数 最近通话最后一次):...

FileNotFoundError: [Errno 2] 没有这样的文件或目录: '/usr/src/app/crt.pem'

有人能告诉我如何解决这个错误吗?

【问题讨论】:

    标签: django daphne


    【解决方案1】:

    安装 tls 和 http2。我看到你已经安装了所有东西。这是为了澄清。

    pip install -U 'Twisted[tls,http2]'
    

    您可以使用自己的 privateKey 和 certKey 进行测试。

    我将在 /home/user/Documents/ssl/ 中运行命令

    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout selfsigned.key -out selfsigned.crt
    

    运行应用程序

    daphne -e ssl:8000:privateKey=/home/user/Documents/ssl/selfsigned.key:certKey=/home/user/Documents/ssl/selfsigned.crt myapp.asgi:application
    

    输出

    user@debian:~/Documents/pythonWeb/myapp$ daphne -e ssl:8000:privateKey=/home/user/Documents/ssl/selfsigned.key:certKey=/home/user/Documents/ssl/selfsigned.crt myapp.asgi:application
        2022-02-04 18:49:12,726 INFO     Starting server at ssl:8000:privateKey=/home/user/Documents/ssl/selfsigned.key:certKey=/home/user/Documents/ssl/selfsigned.crt
        2022-02-04 18:49:12,726 INFO     HTTP/2 support enabled
        2022-02-04 18:49:12,726 INFO     Configuring endpoint ssl:8000:privateKey=/home/user/Documents/ssl/selfsigned.key:certKey=/home/user/Documents/ssl/selfsigned.crt
        2022-02-04 18:49:12,733 INFO     Listening on TCP address 0.0.0.0:8000
        2022-02-04 18:49:27,644 INFO     file_cache is only supported with oauth2client<4.0.0
        192.168.1.106:50128 - - [04/Feb/2022:18:49:32] "GET /stream_1/" 200 2510
        192.168.1.106:58251 - - [04/Feb/2022:18:49:32] "WSCONNECTING /ws/chat/stream_1/" - -
        connect
    

    如果您有来自 Let's Encrypt 的“.pem”文件,请将它们粘贴到自签名文件的位置。

    【讨论】:

      猜你喜欢
      • 2018-02-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 2017-01-03
      • 2018-03-22
      相关资源
      最近更新 更多