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.conf
see 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.conf
there are no rules configured in itself, and the main rules are in conf.d
the 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.conf
In 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.html
the 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 reload
the command to restart nginx.
6. After the project is upgraded, restore nginx.conf
it:
#正常情况用这个
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
.