Python 为什么我的nginx endpoint通过ffmpeg流式传输音频失败,并出现“错误”;收到意外的TLS数据包“;

Python 为什么我的nginx endpoint通过ffmpeg流式传输音频失败,并出现“错误”;收到意外的TLS数据包“;,python,docker,nginx,ssl,ffmpeg,Python,Docker,Nginx,Ssl,Ffmpeg,我正在使用nginx将请求代理到flask/gunicornapi。对于我的大多数端点,它工作得非常完美——然而,我有一个端点提供音频响应(通过ffmpeg),无论我尝试什么,它似乎都不工作。通过docker处理一切 这是我的nginx配置: server { listen $PORT; root /usr/share/nginx/html; index index.html index.html; access_log /var/log/nginx/reverse-acces

我正在使用nginx将请求代理到flask/gunicornapi。对于我的大多数端点,它工作得非常完美——然而,我有一个端点提供音频响应(通过ffmpeg),无论我尝试什么,它似乎都不工作。通过docker处理一切

这是我的nginx配置:

server {
  listen $PORT;
  root /usr/share/nginx/html;
  index index.html index.html;

  access_log /var/log/nginx/reverse-access.log;
  error_log /var/log/nginx/reverse-error.log;

  location / {
    try_files $uri /index.html =404;
  }

  location /api/stream_audio_file {
    proxy_pass          http://backend;
    proxy_http_version  1.1;
    proxy_set_header    Connection "keep-alive";
    proxy_set_header    Host $host;

    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Host $server_name;
  }
下面是python的核心代码http://backend/api/stream_audio_file (通过烧瓶,gunicorn)

当我测试这个端点时,我将完整的ffmpeg日志粘贴到这里: 对于导入,它似乎可以正确获取mp3 url,但失败并出现错误:

[tls @ 0x555bf3011a80] An unexpected TLS packet was received.
https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3: I/O error
[out_0_0 @ 0x555bf302ab00] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
我试过很多东西:

  • 此端点在没有nginx的情况下工作。我试着只查询运行w/just gunicorn的端点,并且正确地返回响应。因此,错误必须与nginx相关
  • 与TLS相关的错误令人困惑——我已经尝试在上设置nginx w/ssl并添加证书,但这无助于/改变错误
  • 我尝试在nginx和python端使用头文件,下面是一些示例:。不起作用
  • Response(flask中带有上下文(..)的流)
    也不起作用
  • 对nginx了解不多,但尝试了一些其他建议,例如通过nginx进行缓冲/无缓冲等,但似乎没有任何效果:(
  • 当我ssh到docker容器中,并运行相同的ffmpeg命令
    ffmpeg-I时https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 -f mp3-to 00:00:02.000-vn-ab 256k-strict-2-loglevel跟踪
    在请求上下文之外,它可以工作!
  • 尝试同时使用openssl和gnutls编译ffmpeg,两者都不起作用/
    tls@error:1408F1BB:SSL例程:ssl3\u get\u记录:错误记录类型
  • 请让我知道什么其他调试信息将是有益的/如果有人有任何假设,我可以测试出来

    [tls @ 0x555bf3011a80] An unexpected TLS packet was received.
    https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3: I/O error
    [out_0_0 @ 0x555bf302ab00] EOF on sink link out_0_0:default.
    No more output streams to write to, finishing.