-1

我正在开发一个使用 Raspberry Pi 构建的网络摄像头。它具有以下组件:

  • 端口 3000 上的 Node.js
  • FFmpeg / FFserver 在端口 8090
  • 前面的 Nginx 通过端口 80/443 (HTTP/HTTPS) 一起代理这些服务

我遇到的问题是,如果 FFserver 在 Nginx 启动时未在端口 8090 上完全准备好stream.mjpeg,即使流正在运行,它也会不断返回 502。这就好像 Nginx 确定主机不存在,然后再也不尝试了。一旦我重新启动/重新加载 Nginx 配置,它就会再次开始工作。

为什么会这样?我是否缺少重试条件?

这是 Nginx 的配置:

server {
  listen 80;
  rewrite ^ https://$host$request_uri? permanent;
}

server {
  listen 443 ssl;

  ssl_certificate /etc/nginx/ssl/nginx.crt;
  ssl_certificate_key /etc/nginx/ssl/nginx.key;

  location / {
    proxy_pass http://localhost:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_next_upstream error timeout http_502;

    # Basic auth
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/htpasswd;
  }

  location /stream.mjpeg {
    proxy_pass http://localhost:8090/stream.mjpeg;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_next_upstream error timeout http_502;

    # Basic auth
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/htpasswd;
  }
}
4

1 回答 1

1

在查看 Nginx 日志后,/var/log/nginx/error.log我可以看到请求将发送到 IPv6 环回地址而不是 IPv4。我换localhost127.0.0.1,问题就解决了。为什么这在重新启动 Nginx 后会起作用,但在此之前不起作用,对我来说仍然是个谜。

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_next_upstream error timeout http_502;

    # Basic auth
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/htpasswd;
  }
于 2016-10-24T19:01:15.633 回答