Timeout settings in Nginx

Source: Internet
Author: User

Reference post: timeout settings in Nginx

When Nginx uses the proxy module, the default read time-out is 60s.

1. Send_timeout

Syntax: Send_timeout the time

Default: Send_timeout

Context: http, server, location

Directive assigns response timeout to client. Timeout is established not on entire transfer of answer, but only between and operations of reading, if after this time CL Ient would take nothing and then Nginx was shutting down the connection.

2.2 parameters for Load balancer configuration: Fail_timeout and Max_fails

These 2 parameters together to control how Nginx thinks that one of the servers in the upstream is invalid when a server connection fails max_fails times in fail_timeout time, Nginx will assume that the server is not working. Also, in the next fail_timeout time, Nginx no longer distributes the request to the failed server.
Personally, Nginx should not take these 2 time with the same parameter fail_timeout to control, if can add a fail_time, to control the next how long, no longer use down the server is better ~
If you do not set these 2 parameters, fail_timeout defaults to 10s,max_fails by default to 1. That is, if one server fails once, the request will not be distributed to the server within the next 10s

3. Proxy_connect_timeout of proxy module

Syntax: proxy_connect_timeout timeout_in_seconds

Context: http, server, location

This directive assigns a timeout for the connection to the ProxyServer. This was not the time until the server returns the pages and this is the Proxy_read_timeout statement. If your proxyserver is up, but hanging (e.g. it does not has enough threads to process your request so it puts Pool of connections to deal with later) and then this statement would not help as the connection to the server have been made. It's necessary to keep in mind, this time the out cannot was more than, seconds.

4. Proxy_read_timeout of proxy module

Syntax: proxy_read_timeout the_time

Default: Proxy_read_timeout

Context: http, server, location

This directive sets the read-timeout for the response of the proxied server. It determines how long NGINX would wait for get the response to a request. The timeout is established isn't for entire response, but only between and operations of reading.

In contrast to proxy_connect_timeout, this timeout would catch a server that puts your in it's connection pool but does not Respond to anything beyond. Be careful though not to set this too low, as your proxy server might take a longer time to respond to requests on purpose (e.g. when serving your a report page, takes some time to compute). You is able though to has a different setting per location, which enables you to has a higher proxy_read_timeout for th E report page ' s location.

If the proxied server nothing would communicate after this time and then Nginx is shut connection.


Another reference: 504 Gateway time-out issues

Web sites that are common to servers that use Nginx as a Web server

I met this problem when I was upgrading the Discuz forum.

In general, this situation may be due to the Nginx default fastcgi process response buffer is too small, which will cause the fastcgi process to be suspended, if your fastcgi service is not good for this suspend processing, then it is very likely to cause 504 Gateway Time-out
Now the site, especially some forums have a lot of replies and a lot of content, a page even has hundreds of K
The default fastcgi process response buffer is 8K, we can set the large point
In nginx.conf, join:

Fastcgi_buffers 8 128k

This means that the fastcgi buffer is set to 8x128k
Of course, if you are doing an immediate operation, you may need to make the Nginx timeout parameter larger, for example, set to 60 seconds:

Send_timeout 60;

Adjust the two parameters, the result is no longer show that timeout, can say the effect is good, but it may be due to other reasons, the current information about Nginx is not many, many things need long-term experience accumulated only results.
$host ;p Roxy_set_header X $remote _addr ;p roxy_set_header X-forwarded-for$proxy _add_x_forwarded_for90 4k;proxy_busy_buffers_size 64k  ; 

Due to the long time of the audit standard nginx configuration as follows:

User Nginx;worker_processes12; Worker_rlimit_nofile102400; Error_log/var/log/nginx/Error.log warn;pid/var/run/nginx.pid;events {use epoll; Worker_connections102400;} HTTP {include/etc/nginx/mime.types; Default_type Application/octet-stream; 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;Keepalive_timeout2048; Send_timeout2048; Fastcgi_connect_timeout2048; #gzip on;include/etc/nginx/conf.d/*. conf; #set the server list for load Balancingupstream MyServer {#the Weigth parameter represents weights, the higher the weight, the greater the chance of being allocated.      #Apache on this machine open 8080 portServer 127.0.0.1:8080; #server 192.168.1.101:80 weight=4 max_fails=2 fail_timeout=25s;     #Ip_hash;} server {Listen80;      server_name xxx.com;      server_name 1xxx.com;         server_name xx.xx.xx.xx; Location ~ ^/nginxstatus/{stub_status on;         Access_log off; } Location/{proxy_pass http://MyServer;      Proxy_redirect off; Proxy_set_header Host$host; Proxy_set_header X-real-ip$remote _addr; #proxy_set_header remote-host $remote _addr;Proxy_set_header x-forwarded- for $proxy _add_x_forwarded_for;      Client_max_body_size 50m;      Client_body_buffer_size 512k; Proxy_connect_timeout1024; Proxy_send_timeout960; Proxy_read_timeout900;      Proxy_buffer_size 128k; Proxy_buffers32128k;                   Proxy_busy_buffers_size 512k; #stub_status off; #启用nginx状态页      }       #define the error prompt page      #Error_page 502 503 504/50.html;        #Location = error/50.html {        #Root/var/www/website;        #}    }}

Timeout settings in Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.