Upstream timed out (110: Connection timed out) while reading response header from upstream

Today I was investigating a weir derror I found on the server logs:

Upstream timed out (110: Connection timed out) while reading response header from upstream

This nginx timeout error was located in a nginx – apache proxy server, where nginx is serving all static content and apache all the dynamic.

Investigating the error and after trying a few fixs, I found this error can happen in two scenarios:

1) Nginx as Proxy, like the one happened to me.

Try adding proxy_read_timeout option into your virtual host configuration, it should look like this:

proxy_read_timeout 150;

Place it inside your root location config:

location / {
        ...
        proxy_read_timeout 150;
        ...
    }

2) Nginx as standalone server with php-fpm or another upstream application.

If this is your case, try adding fastcgi_read_timeout option:

fastcgi_read_timeout 150;

With your php-fpm configuration it should look like this:

location ~* .php$ {
    include         fastcgi_params;
    fastcgi_index   index.php;
    fastcgi_read_timeout 150;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
}

On both cases, just restart nginx to apply the changes.

Note: some scripts may need to increase/decrease the “150″ value I posted here.

Popular search terms:

3 Comments

  1. Backround of the issue:
    When I try to upload a file over http or https, it seems to go okay and after 60 seconds it dies with a message,
    Timeout sending the file:
    perhaps your browser does not send files correctly,
    your session has expired,
    or there was a server error.
    Please try again.

    Architecture:
    User-nginx-tomcat

    What backend uploader we are using?
    gwt file uploader

    Environment:
    Centos 6.5

    Tomcat:
    7.x

    What did i try so far in last 48-72 hours ? Why are we certain its nginx configuration issue?
    1. httpd (Apache/2.4.4), another web server works perfect (just for upload) but we dont want to do it for obvious benefits of nginx
    2. if we remove web server altogether, upload works flawlessly.
    3. played with nearly all timeouts on nginx without luck
    4. tried nginx v1.6 (and 1.5x too) without luck
    5. multiple browsers same result – firefox/chrome windows, firefox/chrome linux
    6. tcpdump and wireshark show data movements for first 60 seconds.
    7. nginx http log – *381 client timed out (110: Connection timed out) while waiting for request, client: IPADD, server: 0.0.0.0:80
    8. nginx https log – *480 client prematurely closed connection, client: IPADDR, server: SERVERNAME, request: “POST /servlet.gupld HTTP/1
    .1″, host: “SERVERNAME”, referrer: “https://SITE/desktopmain.htm”

    Nginx:
    nginx version: nginx/1.6.0
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
    TLS SNI support enabled
    configure arguments: –prefix=/apps/nginx –user=nginx –group=nginx –with-file-aio –with-ipv6 –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_xslt_module –with-http_image_filter_module –with-http_geoip_module –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_degradation_module –with-openssl=/apps/nginx/openssl –with-pcre=/apps/nginx/pcre –with-zlib=/apps/nginx/zlib –with-http_stub_status_module –with-http_perl_module –with-debug –pid-path=/apps/nginx/nginx.pid –error-log-path=/apps/nginx/logs/error.log –http-log-path=/apps/nginx/logs/access.log –http-client-body-temp-path=/apps/nginx/tmp/client_body –http-proxy-temp-path=/apps/nginx/tmp/proxy –http-fastcgi-temp-path=/apps/nginx/tmp/fastcgi –lock-path=/apps/nginx/lock/subsys/nginx

    ————————-nginx.conf, START————————-

    worker_processes 1;

    worker_rlimit_nofile 200000;

    events {
    worker_connections 1024;
    }

    http {
    include 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 logs/access.log main;
    error_log logs/error.log;

    sendfile on;
    send_timeout 10;
    keepalive_timeout 30;
    keepalive_requests 100000;
    reset_timedout_connection on;
    client_body_timeout 10;
    client_header_timeout 10;
    gzip on;
    gzip_min_length 10240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
    gzip_disable “MSIE [1-6]\.”;

    upstream appcluster {
    # least_conn;
    server localhost:8080 fail_timeout=20s;
    keepalive 8;
    }

    server {
    listen 80;
    server_name site.com;
    if ($ssl_protocol = “”) {
    rewrite ^ https://$server_name$request_uri? permanent;
    }
    }

    server {
    listen 443 default ssl;
    root /apps/nginx/html;
    server_name site.com;
    ssl on;
    ssl_certificate /apps/nginx/conf/mycerts/site.crt;
    ssl_certificate_key /apps/nginx/conf/mycerts/site.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    location / {
    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;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass https://appcluster;
    # proxy_pass https://localhost:8080;
    }
    }
    }

    ————————-nginx.conf, END————————-

    Thanks in advance for your suggestions/comments!

  2. HI

    We have one java applet application with dynamic contents. I configure the nginx as reverse proxy to forward the logs to java application server.

    but I am getting “Upstream timed out (110: Connection timed out) while reading response header from upstream”

    how can I solve that

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>