Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the nginx request timeout?

Tags:

nginx

My web server is processing a huge file and then sending a response. I have tried the various nginx timeout parameters without luck. I have tried the parameters recommended in this question, however, I still see the timeout page with the error in the nginx error logs.

1 upstream prematurely closed connection while reading response header from upstream,client: 10.0.42.97, server: 

Here is my nginx.conf

http {
     include       /etc/nginx/mime.types;
     default_type  application/octet-stream;

     access_log    /var/log/nginx/access.log;

     sendfile on;
     tcp_nopush on;
     tcp_nodelay on;

     keepalive_timeout  65;

     client_header_timeout 600;
     client_body_timeout 600;
     send_timeout 600;
     proxy_read_timeout 600;

     fastcgi_buffers 8 16k;
     fastcgi_buffer_size 32k;
     fastcgi_read_timeout 600;

     gzip  on;
     gzip_http_version 1.0;
     gzip_comp_level 2;
     gzip_proxied any;
     gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;

     server_names_hash_bucket_size 64;

     include /etc/nginx/conf.d/*.conf;
     include /etc/nginx/sites-enabled/*;
     }

I am still seeing the 502 Bad gateway from time to time, with the above error. Any pointers on what could be wrong? My input file is a csv file, if that helps. Any pointers or recommendations?

How can I fix this? How can I increase the timeout time?

like image 268
Vinodh Avatar asked Feb 08 '13 00:02

Vinodh


People also ask

How can increase nginx server connection timeout?

For example, you want to increase request timeout to 300 seconds. Then you need to add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives to http or server block. Here the http block allows the changes in all server in NGINX.

Can we increase gateway timeout?

Try Reloading the Webpage One of the first things you can try when encountering a 504 Gateway Timeout error is to wait a few minutes and try reloading the page. You can press the F5 keyboard shortcut to refresh/reload the webpage in most browsers.


1 Answers

Nginx is not the problem here, it is the script which processes the file you are uploading. If you are using PHP, you have to change the settings in your php.ini to allow for a longer timeout and bigger uploads. Possible settings to increase could be:

max_execution_time
max_input_time
memory_limit
post_max_size
upload_max_filesize

If you are using a different scripting language, you should look for settings which control maximum upload sizes, maximum script execution time and memory limits. So long as Nginx returns bad gateway errors, usually there is something wrong with your processing backend.

like image 84
iquito Avatar answered Sep 29 '22 19:09

iquito