在Nginx配置中,可以通过以下指令来设置超时:
proxy_connect_timeout
:设置与后端服务器建立连接的超时时间。单位为秒,默认值为75秒。
示例:
proxy_connect_timeout 30s;
proxy_send_timeout
:设置向后端服务器发送请求的超时时间。单位为秒,默认值为75秒。
示例:
proxy_send_timeout 30s;
proxy_read_timeout
:设置从后端服务器读取响应的超时时间。单位为秒,默认值为75秒。
示例:
proxy_read_timeout 30s;
send_timeout
:设置向客户端发送响应的超时时间。单位为秒,默认值为75秒。
示例:
send_timeout 30s;
keepalive_timeout
:设置长连接的超时时间。单位为秒,默认值为75秒。
示例:
keepalive_timeout 30s;
要修改这些超时设置,请在Nginx配置文件中的http
、server
或location
块中添加相应的指令。例如,如果你想要为特定的server
块设置超时,可以在该server
块中添加以下指令:
http {
...
server {
...
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
send_timeout 30s;
keepalive_timeout 30s;
...
}
}
修改完成后,保存配置文件并重新加载Nginx以使更改生效:
sudo nginx -t # 检查配置文件语法是否正确
sudo nginx -s reload # 重新加载配置文件