连接到上游时没有上游,但是上游是可以的

MID*_*E11 12 nginx

我对NGINX有一个非常奇怪的问题.

我有以下upstream.conf文件,上面有以下内容:

upstream files_1 {
    least_conn;
    check interval=5000 rise=3 fall=3 timeout=120 type=ssl_hello;

    server mymachine:6006 ;
}
Run Code Online (Sandbox Code Playgroud)

在locations.conf中:

location ~ "^/files(?<command>.+)/[0123]" {
        rewrite ^ $command break;
        proxy_pass https://files_1 ;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Run Code Online (Sandbox Code Playgroud)

在/ etc/hosts中:

127.0.0.1               localhost               mymachine
Run Code Online (Sandbox Code Playgroud)

当我这样做时wget https://mynachine:6006/alive --no-check-certificate,我明白了HTTP request sent, awaiting response... 200 OK.我还验证了端口6006正在使用netstat进行监听,并且可以.

但是当我向NGINX文件服务器发送请求时,我收到以下错误:

连接上游时没有上游,客户端:..,请求:"POST/files/save/2 HTTP/1.1,上游:" https:// files_1/save "

但上游还可以.问题是什么?

Ang*_*ira 11

定义upstreamNginx 时,会处理目标服务器以及可以启动或关闭的内容。Nginx 根据fail_timeout(默认 10s)和max_fails(默认 1)决定你的上游是否关闭

因此,如果您有一些慢速请求超时,Nginx 可以确定您上游的服务器已关闭,并且因为您只有一个,整个上游实际上已关闭,并且 Nginx 报告no live upstreams. 在这里更好地解释:

https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/

我遇到了类似的问题,您可以防止覆盖这些设置。

例如:

upstream files_1 {
    least_conn;
    check interval=5000 rise=3 fall=3 timeout=120 type=ssl_hello max_fails=0;
    server mymachine:6006 ;
}
Run Code Online (Sandbox Code Playgroud)

  • 根据文档,这似乎是“health_check”,而不是“check”,并且是 Nginx Plus(高级)功能。 (3认同)
  • 奇怪的是,如果只有一个上游,它应该永远不会禁用它,但有时如果它有 ipv6 和 ipv4,则将其视为两个 /sf/answers/4124732601/ 所以是的,这是正确的...不知何故之前的请求此“超时”或将上游标记为失败,另请参阅 /sf/answers/3678553091/ (2认同)

job*_*wat 8

我有同样的错误no live upstreams while connecting to upstream

我的与 SSL 相关:添加proxy_ssl_server_name on解决了它。

location / {
    proxy_ssl_server_name on;
    proxy_pass https://my_upstream;
  }
Run Code Online (Sandbox Code Playgroud)