本文介绍了连接上游时没有上游上游,但可以上游的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对NGINX感到非常奇怪.

I have a really weird issue with NGINX.

我有以下upstream.conf文件,并且具有以下上游文件:

I have the following upstream.conf file, with the following upstream:

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

    server mymachine:6006 ;
}

在locations.conf中:

In 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;
}

在/etc/hosts中:

In /etc/hosts:

127.0.0.1               localhost               mymachine

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

When I do: wget https://mynachine:6006/alive --no-check-certificate, I get HTTP request sent, awaiting response... 200 OK. I also verified that port 6006 is listening with netstat, and its OK.

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

But when I send to the NGINX file server a request, I get the following error:

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

But the upstream is OK. What is the problem?

推荐答案

在定义upstream时,Nginx会处理目标服务器以及可以启动或关闭的设备. Nginx根据fail_timeout(默认值为10s)和max_fails(默认值为1)决定上游是否关闭

When defining upstream Nginx treats the destination server and something that can be up or down. Nginx decides if your upstream is down or not based on fail_timeout (default 10s) and max_fails (default 1)

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

So if you have a few slow requests that timeout, Nginx can decide that the server in your upstream is down, and because you only have one, the whole upstream is effectively down, and Nginx reports no live upstreams. Better explained here:

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

我遇到了类似的问题,您可以防止此操作覆盖那些设置.

I had a similar problem and you can prevent this overriding those settings.

例如:

upstream files_1 {
    least_conn;
    check interval=5000 rise=3 fall=3 timeout=120 type=ssl_hello max_fails=0;
    server mymachine:6006 ;
}

这篇关于连接上游时没有上游上游,但可以上游的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 08:42