故事來了
在很久很久以前我們的主人公小猿開了一家飯店取名為Nginx,並且兼職客棧的廚師,因為小猿廚藝甚是了得,於是沒過多久十里八村的人都都會到Nginx客棧做客,每天生意非常火爆,但是因為廚師只有小猿一人,所以排隊的人非常多,小猿看着鄉親們排隊,心里面也過意不去,於是為了節約鄉親們的時間,小猿設置了超時時間,客人到店里面排隊—>點菜—>炒菜—>菜上桌的時間為X,點菜—>菜上桌—>菜上桌時間為Y,菜上桌—>菜上桌時間為Z,超過設置的時間小猿就免費送給顧客們一份點心。至此小猿的生意更是火爆非常!
nginx中超時設置、請求超時、響應等待超時配置:
proxy_connect_timeout :后端服務器連接的超時時間_X
proxy_read_timeout:連接成功后_Y
proxy_send_timeout :后端服務器數據回傳時間_Z
nginx使用proxy模塊時,默認的讀取超時時間是60s。
nginx.conf配置:
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 12s;
types_hash_max_size 2048;
client_max_body_size 3000m;
# proxy_connect_timeout 1200;
# proxy_send_timeout 1200;
# proxy_read_timeout 1200;
# send_timeout 1200;
include /etc/nginx/mime.types;
default_type application/octet-stream;
...
}
以為到這就結束了嗎?NO.
配置完以后如果超時我們期待的返回碼應該是503,然而返回的確實404
最初看到404以為是請求沒有找到接口,仔細查看后因為是nginx報的404,所有是nginx內部去查找超時503頁面時,沒有找到所以報了404.