How to configure nginx maintenance page

1. Description

My company generally publishes projects without stopping, but in case of special circumstances, we have to stop the project release, and users will not be able to use it for several hours.

When the release of the project is stopped, nginx will be modified so that all requests will jump to the maintenance page, and the modification method will be recorded here.

Two, nginx configuration maintenance page method

1. First find the path where nginx is installed on your server.

2. You can write a simple html page for maintenance updating.html, for example:

<html>
<header></header>
<body>
<h1>尊敬的用户,系统目前正在升级,请稍后再试,给您带来的不便敬请谅解,谢谢</h1>
</body>

It can be placed in the html folder in the nginx directory of the server, for example /home/admin/nginx/html/updating.html
(there is usually index.html that comes with nginx in this folder)

3. You can check and /home/admin/nginx/conf/nginx.confsee how it is configured; for example, my own is written at the bottom:

    #正常情况用这个
    include /home/admin/nginx/conf.d/*.conf;
    #维护时用这个
   # include /home/admin/nginx/conf/weihu.conf;

It means that nginx.confthere are no rules configured in itself, and the main rules are in conf.dthe folder;
in this way, it can be switched to:

    #正常情况用这个
   # include /home/admin/nginx/conf.d/*.conf;
    #维护时用这个
    include /home/admin/nginx/conf/weihu.conf;

4. /home/admin/nginx/conf/weihu.confIn the file, it is configured like this:

server {

    listen  80;
    server_name  10.1.2.3;

    #直接让请求跳转到updating.html
    rewrite ^(.*)$ /updating.html break;
    #由于Nginx不允许静态文件响应POST请求,故此处将“405 not allowed”修改为“200 ok”
    error_page 405 =200 $uri;
}

server {
      
    listen  8080;
    server_name  10.1.2.3;

	#直接让请求跳转到updating.html
    rewrite ^(.*)$ /updating.html break;
    #由于Nginx不允许静态文件响应POST请求,故此处将“405 not allowed”修改为“200 ok”
    error_page 405 =200 $uri;
}

(Among them, the server_name I configured is the local ip, which is not very important)

Among them, mainly rewrite ^(.*)$ /updating.html break;, this allows the request to go directly to updating.htmlthe page, which is the maintenance page.

All requests to access ports 80 and 8080 of this nginx server will be redirected to the maintenance page.

5. Use /home/admin/nginx/sbin/nginx -s reloadthe command to restart nginx.

6. After the project is upgraded, restore nginx.confit:

    #正常情况用这个
    include /home/admin/nginx/conf.d/*.conf;
    #维护时用这个
   # include /home/admin/nginx/conf/weihu.conf;

Don't forget to restart nginx, /home/admin/nginx/sbin/nginx -s reload.

Guess you like

Origin blog.csdn.net/BHSZZY/article/details/129447310