# 连接上游时没有可用的上游服务器

- **ID:** `nginx/no-live-upstreams-while-connecting-to-upstream`
- **领域:** nginx
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

upstream块中的所有上游服务器均被标记为故障或健康检查失败，导致没有可用目标。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| nginx 1.24.0 | active | — | — |
| nginx 1.22.1 | active | — | — |
| nginx 1.26.0 | active | — | — |

## 解决方案

1. ```
   Check upstream server health and restart them: systemctl restart myapp. Also verify health_check settings in nginx.conf and ensure backup servers are defined: server backup1.example.com backup;
   ```
2. ```
   Temporarily mark a server as up with max_fails=0 fail_timeout=0 in the upstream block: server 10.0.0.1:8080 max_fails=0 fail_timeout=0;
   ```

## 无效尝试

- **Increase worker_connections to 10240** — This error is about upstream availability, not connection limits. Increasing worker_connections cannot revive dead upstream servers. (95% 失败率)
- **Set proxy_next_upstream to always retry** — proxy_next_upstream only works if there is at least one live upstream. If all are dead, retry logic is useless. (85% 失败率)
