Nginx设置公告维护页面(所有页面重定向到公告页面)

2021-01-01 1373点热度 1人点赞 1条评论

有时候网站维护可能需要一段时间,为了给用户看到一个比较友好的提示,可以在nginx上配置公告页面,用户访问的所有页面都定向到这个页面。

nginx.conf配置
server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;
    #以下放到nginx的config中,然后注释掉原来location中的/的部分,
    #维护好了以后,maintain.html redirect到/
    
    #rewrite ^/maintain.html$ http://www.example.com/ redirect;
    location / {
        return 502;
    }

    #在 /usr/share/nginx/html/maintain目录下放静态维护的页面maintain.html
   
    #maintain.html的内容见下面
    error_page   502  maintain.html;
    location = /maintain.html {
        root   /usr/share/nginx/html/maintain;
    }

}

mantain.html
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="refresh" content="20;URL='/'" />

    <title>网站维护中</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        /* Sticky footer styles
-------------------------------------------------- */
        html {
            position: relative;
            min-height: 100%;
        }

        body {
            /* Margin bottom by footer height */
            margin-bottom: 60px;
        }

        .footer {
            position: absolute;
            bottom: 0;
            width: 100%;
            /* Set the fixed height of the footer here */
            height: 60px;
            background-color: #f5f5f5;
        }


        /* Custom page CSS
-------------------------------------------------- */
        /* Not required for template or sticky footer method. */

        .container {
            width: auto;
            max-width: 680px;
            padding: 0 15px;
        }

        .container .text-muted {
            margin: 20px 0;
        }
    </style>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

    <!-- Begin page content -->
    <div class="container">
        <div class="page-header">
            <h1>系统停运维护公告</h1>
        </div>
        <p class="lead">为了给用户更好的体验,我们正在对网站进行维护,带来不便,敬请谅解!</p>
        <div class"center-block" style="text-align:center;">
            <a href="/" class="btn btn-primary">刷新</a>
        </div>

    </div>

    <footer class="footer">
        <div class="container">
            <p class="text-muted">某某网站 联系方式:XXXX</p>
        </div>
    </footer>


</body>

</html>

 

admin

这个人很懒,什么都没留下

文章评论

  • kafrots

    Radoif Pharmacie En Ligne Viagra En Valence best price for generic cialis Igvuer comprar cialis recomendado Mvcknm Cqanpd Cialis

    2022-04-15
  • 您需要 登录 之后才可以评论