Tuesday, May 10, 2016

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

If you encounter the following error in logs/error.log in Nginx:

2016/05/10 22:59:24 [error] 20722#0: *56830 connect() failed (110: Connection timed out) while connecting to upstream, client: 1.2.3.4, server: localhost, request: "GET /api/v1/events/xxx HTTP/1.1", upstream: "http://127.0.0.1:8080/api/v1/events/xxx", host: "api.izeye.com", referrer: "https://www.izeye.com/"

you can fix by setting keepalive between Nginx and Tomcat as follows:

    upstream backend {
        server localhost:8080;

        keepalive 32;
    }

    server {
        listen       80;
        ...
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
        }
        ...
    }

No comments:

Post a Comment