Y
Y
Yaroslav2019-03-27 19:17:09
Nginx
Yaroslav, 2019-03-27 19:17:09

How to configure nginx to block access to the site and direct to the stub during maintenance?

There is a big nginx config with different location and proxy_pass on httpd. It is necessary to cut off httpd for a while and redirect all requests to a static page (stub) in another directory. What and where to write in the config for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Mezhuev, 2019-03-27
@CubaJas

An example of implementing a stub output when the backend is unavailable:

error_page 502 503 504 /maintenance.htm;
location ~ /maintenance\.(css|htm|jpg) {
        root /usr/share/nginx;
}

This preserves the original address of the request. Another convenience is that these parameters can be put in a separate file and connected as needed via include for any set of sites. Additionally, you can organize automatic page reloading, for example, by adding the following line to the maintenance.htm file:
<meta http-equiv="refresh" content="30" />

D
Dmitry Derepko, 2019-03-27
@xEpozZ

location / {
    return 302 site.com/stub.html;
}

before all locations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question