Score:0

How to make Nginx reverse proxy wait until upstream comes online?

pe flag

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?

Ivan Shatsky avatar
gr flag
As a workaround you can try to put your upstream name into the variable like shown in [this](https://sandro-keil.de/blog/let-nginx-start-if-upstream-host-is-unavailable-or-down/) article. However I don't know this will behave with sockets, so if you'll try it, please provide some feedback.
djdomi avatar
za flag
you could configure nginx to serve stale content?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.