0

Nginx config

server {
    listen        *:80;
    server_name   live.domain.com;

    server_tokens off;
    charset utf-8;

        error_log       /var/log/nginx/live-error.log info;
        access_log      /var/log/nginx/live-access.log;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 http://127.0.0.1:1337;
        proxy_redirect off;
    }
}

When node.js is working everything is okay, but if node.js not started and I try to load page http://live.domain.com/socket.io/socket.io.js it makes me wait 30 seconds (read_timeout).

I want make it so, that if node.js not running I'm getting 404 or 502 error right away without 30 seconds waiting for timeout.

In other words: I need to check node.js on client side right away.

1

A flexible solution would be to use upstream:

upstream backend {
    server 127.0.0.1:1337    max_fails=1 fail_timeout=5s;
}

server {
    listen        *:80;
    server_name   live.domain.com;

    server_tokens off;
    charset utf-8;

        error_log       /var/log/nginx/live-error.log info;
        access_log      /var/log/nginx/live-access.log;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 http://backend;
        proxy_redirect off;
    }
}

This way you can additionally control how many failures are tolerated and you can have multiple servers in one upstream.

0

Set proxy_connect_timeout to lower value:

proxy_connect_timeout 2s;
0

Please see my answer here, there could also be a problem with csf if you're on Linux:

https://serverfault.com/a/713874/150138

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.