At the end of last week, the brothers project was going to expand the server to provide better services , Brother project has some functions that are provided to me in real time , I need to temporarily block the corresponding system functions , Because use nginx, So you can configure it directly nginx Redirect to fixed system maintenance page .

nginx Redirection is actually very simple , use return  or rewrite All keywords are OK , Because retargeting jumps back directly to the static page , No subsequent operations and records are required , So direct 301 Permanent redirection .

Redirection can be done in server Middle configuration , It can also be in specific location  Middle configuration , Here is a brief introduction .

stay server Middle configuration :

http {
listen 80;
server_name; # following return or rewrite Just choose one of them . among upgrade.html It's a reminder page written by myself
return 301;
# rewrite ^/(.*)$ permanent;
 location / {
# The following configuration content is omitted here

Or in location Middle configuration :

http {
listen 80;

location / {
rewrite ^/(.*)$ permanent;
 # The following configuration content is omitted here 

It can be seen from the above examples that ,return  use 301 Parameter redirection ,rewrite use  permanent( Of course, it can also be used break,last, If you want to make a difference, look up the information yourself ).

I don't know if you have found , In the above two examples , It's all used  To redirect to , I tried , use Redirect directly to, It will report an error and repeat too many times , It's going into a dead cycle . It can be configured to manage multiple domain names at the same time A Redirect B, But if there is only one domain name A How to do that ?

This is the time to use if The conditions are right , Here we are in server For example, the configuration in the :

http {
listen 80;
server_name; # Be careful if There must be a space after !!!
if ($request_uri !~ "/upgrade.html$") {
return 301;
} location / {
# The following configuration content is omitted here

The above examples show that , When the access path does not contain /upgrade.html  And then redirect to  upgrade.html, At this point, you can redirect , There won't be too many repetitions , But there's another problem , Namely upgrade.html The picture in cannot be displayed , There's no time to study how to avoid redirection of images , I'll add later .

test if conditional , I met a special pit , Is to add if Restart after nginx Report errors :

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

Input  systemctl status nginx.service  You can view error messages , among   nginx: [emerg] unknown directive "if($request_uri"  Error finding the answer , Turned out to be if There must be a space after it !!!!, It's too much , The introductions on the Internet nginx if None of my articles mentioned such important information ...

Thank you for the information :

if There must be a space after :

nginx in return and rewrite:

nginx More related articles redirected to the system maintenance page

  1. nginx Redirection rules in detail

    Why use 301 Redirect There are many cases in website construction that need web page redirection : Such as changes in the structure of the web directory , Page rename . Page extension changed . Website domain name change, etc . If you don't redirect , Users' collections and old addresses in the search engine database can only give visitors one 4 ...

  2. nginx Redirect explain

    One .nginx See the previous essay for the installation of the two operating systems ( Installed please skip ) linux To build nginx windows To build nginx Two .Nginx Redirect —— Go straight to the project , Instead of nginx The welcome page Default ngin modify n ...

  3. Nginx Set up temporary maintenance page

    Nginx Set up temporary maintenance page ...

  4. linux in nginx Summary of redirection methods

    linux in nginx 301 Redirection jump method summary Case one : visit aaaaaaa Station to bbbbbbbbbbb standing Copy the code as follows : server { server_naaaaaaame www.aa ...

  5. nginx rewrite arg Address forwarding parameter processing with question mark ?Nginx The parameter problem of redirection

    Nginx The parameter problem of redirection Writing to a website rewrite When redirecting rules , Encountered this problem about redirection parameter processing . By default ,Nginx It's going on rewrite After that, the parameter part of the old address will be added automatically , And that's good for redirecting to ...

  6. nginx Getting started with redirection rules

    nginx An introductory example of redirection rules Time :2015-12-17 15:18:03 source : The Internet Reading guide :nginx Redirection rules ,Nginx The redirection module of HttpRewriteModule Instructions for use ,nginx Redirect ...

  7. stay CentOS To build nginx To deploy a static page website

    stay centOs To build nginx To deploy a static page website One . Deploy the server environment nginx: Lightweight . High performance HTTP And reverse proxy server , Less memory , Strong concurrency , Compared to the old apache As web The server , Better performance ...

  8. wordpress Register and redirect to custom page

    wordpress How to redirect to a custom page after registration ? Add the following code to the functions.php In the file add_filter( 'registration_redirect', 'w ...

  9. Aliyun server ECS On ubuntu install nginx Post default site page open error , Shows that this site cannot be accessed

    problem : In the new Alibaba cloud server ECS Installation on nginx Failed to open the default page after , As shown in the figure below . System environment :Ubuntu 16.04.4 LTS64 edition . Step review : root Run the command from the user apt-get inst ...

  10. WordPress The user logs in and redirects to the specified page

    This article will show you WordPress Tips on how to redirect users to specific pages or articles after login . One . Redirect to the site administration panel . Add the following code to the functions.php In file : function  ...

Random recommendation

  1. [Android]Volley Use

    Volley yes Google I/O 2013 What is put forward in this paper is Android Projects that provide simple and fast network access .Volley It is especially suitable for the scene with small amount of data but frequent communication . advantage Compared with other network loading libraries ,Volley Superior officials ...

  2. SNMP Remote monitoring of process information OID

    There's a project that needs to be used recently snmp Remote monitoring process information . So I checked the information . One . Information ...

  3. Linux install oracle 10g Frequently asked questions ——OUI-25031

    OUI-25031:Some of the configuration assistants failed/cancelled. This is one of the common errors in the installation process . The cause of this error :/etc/hosts ...

  4. Spring Integrate freemarker Send E-mail

    Reprint : classification : freemarker spring 2014-06-20 23:39 752 Human reading ...

  5. Hadoop datanode Unable to start error

    Start up Hadoop In the process of distributed deployment , Find out datanode No normal startup , Check the log and find out the error : Incompatible clusterIDs in /op ...

  6. C#- High blood pressure lifestyle data simulation

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace test ...

  7. 《 The illustration HTTP》 Reading notes ( 7、 ... and : Communication data forwarding program - agent / gateway / Tunnel )

    HTTP When communication , In addition to clients and servers , There are also applications for communication data forwarding , For example, agency . Gateways and tunnels , They can work with the server . These servers and applications can forward requests to the next server on the communication line , And can receive from that suit ...

  8. In quick order Java and python Realization , It's actually available

    1. The basic idea Quick sort each sort determines one element x The location of , The way to use it is Will be greater than the element x The value of x To the right of , Less than element x The value of x Left side . When you are sure x After the position of , And then separate them from each other x The array on the left and the array on the right can be sorted quickly . 2. ...

  9. Android scrollbar Set up

    insideOverlay: The default value is , It means that padding Area and covered view On insideInset: It means that padding Area and inserted in view Back outsideOverlay: It means that pad ...

  10. java Study Command line run java Program

    Learn before python, Because the company needs . Now I have to turn java. 1. The command runs java Program . Program name code: /** * Created by liumeide on 2017/ ...