fastcgi_connect_timeout
为尝试连接 FastCGI 服务器设置超时时间。 — NGINX HTTP Core
fastcgi_connect_timeout
httpserverlocation
语法fastcgi_connect_timeout time;
默认值60s
上下文http, server, location
模块NGINX HTTP Core
参数1
说明
The `fastcgi_connect_timeout` 指令指定 NGINX 在连接到 FastCGI 服务器之前等待的最长时间,然后才会使请求失败。这个超时在你的 FastCGI 服务器负载很高或响应较慢时尤为关键,因为它有助于防止 NGINX 在等待建立连接时无限期挂起。如果在指定的时间范围内无法建立连接,请求将被中止,并向客户端返回 504 Gateway Timeout 错误。 此指令在 `http`、`server` 或 `location` 的配置上下文中设置,允许全局配置或针对某些 server 块或 location 路径进行特定配置。`fastcgi_connect_timeout` 的值以秒为单位指定,可以设置为正整数。根据 FastCGI 服务器的预期响应时间选择合适的值很重要,既不能太长(会导致不必要的延迟),也不能太短(会导致过早超时)。
配置示例
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_connect_timeout 30s;
include fastcgi_params;
}⚠
将值设置得过低可能会导致在正常负载情况下频繁超时。
⚠
确保其他超时设置(例如 `fastcgi_read_timeout`)与此指令不冲突。
⚠
必须遵守配置上下文的限制;在无效上下文之外设置此指令会导致错误。