1

I have a server app that listens on a UNIX socket, and Nginx serving as a reverse proxy.

Now I want Nginx to wait until my app comes online when e.g. I deploy an update and restart it, without returning any errors to the clients.

This is what I have in my Nginx config:

location / {
#   proxy_pass http://localhost:8080;
    proxy_pass http://unix:/tmp/MyApp.sock;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_cache_bypass $http_upgrade;

    proxy_connect_timeout 60;
    proxy_send_timeout 60;
    proxy_read_timeout 60;
}

However, whenever my app is down Nginx returns 502 Bad Gateway immediately. Apparently none of the proxy_*_timeout settings help.

Same happens with a local TCP socket. With UNIX sockets, when I shut down the app I make sure the socket file is deleted, so that Nginx can see there's no app running.

How can I tell it to actually wait for a certain period of time until the socket becomes available?

2
  • As a workaround you can try to put your upstream name into the variable like shown in this article. However I don't know this will behave with sockets, so if you'll try it, please provide some feedback. May 14, 2022 at 7:35
  • you could configure nginx to serve stale content?
    – djdomi
    May 14, 2022 at 10:59

1 Answer 1

1

Proxy timeouts are timeouts for the socket, but if the socket cannot be stablished they make no difference. I think the functionality you are after is provided as an extra in NginX Plus. That's a paid sofware.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .