美文网首页
Nginx-14 错误页面配置

Nginx-14 错误页面配置

作者: Habit_1027 | 来源:发表于2020-01-13 19:53 被阅读0次

    nginx错误页面包括404 403 500 502 503 504等页面,只需要在server中增加以下配置即可:

    # 声明错误页面 错误返回码 错误页面的 url
    error_page  404   /404.html;
                    location = /404.html {
                            root   /usr/share/nginx/html;
                    }
    

    注意:

    /usr/local/share/html/ 路径下必须有404.html这个文件!!!

    404.html上如果引用其他文件的png或css就会有问题,显示不出来,因为其他文件的访问也要做配置;
    为了简单,可以将css嵌入文件中,图片用base编码嵌入;如下:

    [root@localhost html]# vim 404.html
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
            <title>404</title>
            <style>
                .layout-table{display:table;height:100%;width:100%;vertical-align: middle;margin-top:150px}
                .layout-table-cell{display: table-cell;vertical-align: middle;text-align:center}
                .layout-tip{font-size:28px;color:#373737;margin: 0 auto;margin-top:16px;border-bottom: 1px solid #eee;padding-bottom: 20px;width: 360px;}
                #tips{font-size:18px;color:#666666;margin-top:16px;}
            </style>
        </head>
        <body class="layui-layout-body">
            <div class="layui-layout layui-layout-admin">
                
                <div class="layui-body">
                    <div class="layout-table">
                        <div class="layout-table-cell">
                            <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV4AAACMCAYAAAA0qsGKAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1s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+N1pSZmYxFpT9uDMqcWCG3OYOZO83F+RWgB/TfIXwtsfDvR2ZnRN43jUd8xpg6/sMYhc6T9kz54WUx4gEhbcpSS4XylLmwDgrzH+Qnj7hSCw/OicWxp2mZkM4en+SNlkhei43ymbaPN6FtuA7SEGgfuch5sKbggvF+iCv0PK8YoGeHTUoB/JricKd41U1PLlQ0fu3LHh9phyqJgeRZN1J/ZgdhBb8LcL/g55cs1V411YEA4jI5vHNguoeHnokbLqhITqrQ7z+JB3LJuUtHvEYhsTAP52yF9UNQA2Qgjkio8uazrTbSajEQ50wBUhC+8HNAdgCdKa25D/9ql9Pe9FEtWY3tb0AsDVUejxAgAAAN0BVQ0AAAAQXgAAAAgvAAAAAOEFAABwF/8VYAAXRwSpGfHzmgAAAABJRU5ErkJggg==" class="layout-img">
                            <p class="layout-tip">哎呀,找不到该页面啦!</p>
                            <p id="tips">请检查您的网络连接是否正常或者输入的网址是否正确</p>
                        </div>
                    </div>
                </div>
            </div>
            
        </body>
    </html>
    

    展示效果;


    image.png

    相关文章

      网友评论

          本文标题:Nginx-14 错误页面配置

          本文链接:https://www.haomeiwen.com/subject/itpnactx.html