nginx比較強大,可以針對單個域名請求做出單個連接超時的配置.
比如些動態解釋和靜態解釋可以根據業務的需求配置
proxy_connect_timeout :后端服務器連接的超時時間_發起握手等候響應超時時間
proxy_read_timeout:連接成功后_等候后端服務器響應時間_其實已經進入后端的排隊之中等候處理(也可以說是后端服務器處理請求的時間)
proxy_send_timeout :后端服務器數據回傳時間_就是在規定時間之內后端服務器必須傳完所有的數據
server
{
listen 80;
server_name www.qq.cn;
index index.jsp index.do index.html;
root /data/webapp/qqroot;
#limit_conn crawler 20;
location /(WEB-INF)/ {
deny all;
}
location / {
proxy_pass http://192.168.1.31:8081;
proxy_connect_timeout 500s;
proxy_read_timeout 500s;
proxy_send_timeout 500s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location ~* (\.jpg)|(\.gif)|(\.png)|(\.swf)|(\.html)|(\.htm)|(\.exe)|(\.flv)|(\.doc)|(\.rar)|(\.rtf)|(\.bmp)|(\.xls)$
{
root /data/webapp/qqroot/;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
}
proxy_connect_timeout
語法: proxy_connect_timeout timeout_in_seconds
上下文: http, server, location
This directive assigns a timeout for the connection to the proxyserver. This is not the time until the server returns the pages, this is the [#proxy_read_timeout proxy_read_timeout] statement. If your proxyserver is up, but hanging (e.g. it does not have enough threads to process your request so it puts you in the pool of connections to deal with later), then this statement will not help as the connection to the server has been made. It is necessary to keep in mind that this time out cannot be more than 75 seconds.
proxy_read_timeout
語法: proxy_read_timeout the_time
默認值: proxy_read_timeout 60
上下文: http, server, location
This directive sets the read timeout for the response of the proxied server. It determines how long NGINX will wait to get the response to a request. The timeout is established not for entire response, but only between two operations of reading.
In contrast to [#proxy_connect_timeout proxy_connect_timeout] , this timeout will catch a server that puts you in it's connection pool but does not respond to you with anything beyond that. Be careful though not to set this too low, as your proxyserver might take a longer time to respond to requests on purpose (e.g. when serving you a report page that takes some time to compute). You are able though to have a different setting per location, which enables you to have a higher proxy_read_timeout for the report page's location.
If the proxied server nothing will communicate after this time, then nginx is shut connection.
proxy_send_timeout
語法: proxy_send_timeout time_in_seconds
默認值: proxy_send_timeout 60
上下文: http, server, location
This directive assigns timeout with the transfer of request to the proxy server. Time out is established not on entire transfer of request, but only between two operations of record. If after this time the proxy server will not take new data, then nginx is shut the connection