2

I have an application that is trying to make ajax requests from a Javascript application to retrieve xml files from an nginx server. Normally everything is fine but I often see errors in the nginx log (and get errors from my applications error reporting) that nginx expriences a timeout during the get:

2015/11/16 21:15:21 [error] 1208#0: *4894044 upstream timed out (110: Connection timed out) while connecting to upstream, client: 209.95.138.54, server: www.servername.com, request: "GET /Shape%20Textures/Metal/Born%20to%20Shine.jpg?agentView=436314 HTTP/1.1", upstream: "http://127.0.0.1:3000/AQO/Shape%20Textures/Metal/Born%20to%20Shine.jpg?agentView=436314", host: "www.servername.com.com", referrer: "https://www.servername.com.com/?nid=39956&mode=edit"

We also sometimes get this similar error:

2015/11/17 19:03:16 [error] 1002#0: *54042 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 137.164.121.52, server: www.servername.com, request: "POST /projects/?q=node/36375/update_project_time_and_stats HTTP/1.1", upstream: "http://127.0.0.1:3000/projects/?q=node/36375/update_project_time_and_stats", host: "www.servername.com", referrer: "https://www.servername.com/AQO/?nid=36375&mode=edit"

I have seem similar posts with similar timeouts but all of those posts seemed reproducible. This issue never happens to me but running on the live server I will see 5-30 of these timeouts a day.

Here is my nginx config:

client_max_body_size 50M;

server {
    server_name servername.com;
    return 301 $scheme://www.servername.com$request_uri;
}

server {
    listen 80;
    listen 443 ssl;
    fastcgi_read_timeout 120;
    ssl_certificate /path/to/ssl/star_servername_com.pem;
    ssl_certificate_key /path/to/ssl/star_servername_com.key;

    # Redirect all non-SSL traffic to SSL.
    if ($ssl_protocol = "") {
      rewrite ^ https://$host$request_uri? permanent;
    }

    root /usr/share/nginx/html;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name www.servername.com;

    location / {
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_pass http://127.0.0.1:3000;
            proxy_read_timeout 120s;
    }
}

Since I can't reproduce it I wonder how might I be able to track down this issue?

Mike2012
  • 7,629
  • 15
  • 84
  • 135

2 Answers2

1

upstream timed out (110: Connection timed out) while connecting to upstream

means that your upstream server didn't accept connection in time

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

means that your upstream server didn't respond with answer in time

So check your upstream server at 127.0.0.1:3000. It may have setup with small number of incoming connections or some sort of DDoS protection or really heavy loaded at the moment or something else.

Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50
  • There is a node.js server running on port 3000 but as far as I can tell node.js doesn't put any limits on incoming connections. Ubuntu has a default incoming connections of 1024 shown by ulimit -n – Mike2012 Nov 26 '15 at 19:21
  • if your Node.js server is heavy loaded or run really long tasks you can try to encrease nginx's [proxy_connect_timeout](http://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) and [proxy_read_timeout](http://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_read_timeout). Their default values are 60 seconds and you may need to increase this settings – Alexander Ushakov Nov 27 '15 at 12:05
1

I would like to refer to this answer which shows how to optimize your settings.

Although not the best solution, but very dependent on what you'd like to achieve, you could simply increase proxy_read_timeout to for example 300.

Community
  • 1
  • 1
jonasvdc
  • 33
  • 1
  • 9