我正在开发一个使用 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;
}
}