A
A
Alexey Segodin2021-04-17 19:08:36
Nginx
Alexey Segodin, 2021-04-17 19:08:36

Redirect if NodeJS application is not running?

Is it possible to configure Nginx to redirect the site visitor to some other address if the NodeJS application is not currently running? If yes, then so?

I don't want users to see a blank page with a 502 Bad Gateway error while I'm doing something with the server.

Here is an excerpt from my virtual host settings. I suspect some changes need to be made. Or not?

root /var/www/site/public;
index index.html;

location / {
    try_files $uri @backend;
}

location @backend {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_cache_bypass $http_upgrade;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Confy, 2021-04-17
@Aleksei_Segodin

I have never worked with nginx, but judging by the documentation and other examples on the same page, if you search for the phrase error_page , something like this should work:

...
index index.html;

error_page 502 https://example.com/;
error_page 404 /404.html;

location / {
    try_files $uri @backend;
...

A
Alexey Dmitriev, 2021-04-17
@SignFinder

https://www.google.com/search?q=nginx+maintenance+page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question