nginx 404错误页面配置详解

nginx 错误页面配置

再主配置文件server中加入一个location模块即可
vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index 404.html;
# rewrite .* http://jd.com permanent;
# 这个是直接转向www.jd.com的页面
}
}

注意:

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

为了简单,可以将css嵌入文件中,图片用base编码嵌入;如下:

[root@localhost html]# vim /usr/share/nginx/html/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="自定义图片地址链接">
                        <p class="layout-tip">哎呀,找不到该页面啦!</p>
                        <p id="tips">请检查您的网络连接是否正常或者输入的网址是否正确</p>
                    </div>
                </div>
            </div>
        </div>
        
    </body>
</html>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VgUGVS47-1602667315967)(assets/1561964133748.png)]

直接用IP地址访问网页就好了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx错误页面配置可以通过error_page指令来实现。该指令的语法是error_page code [ code... ] [ = | =answer-code ] uri | @named_location。在配置文件中,我们可以使用error_page指令来定义当发生特定错误时显示预定义的URI。例如,可以使用以下配置来定义当发生502或503错误时显示50x.html页面: error_page 502 503 /50x.html; location = /50x.html { root /usr/share/nginx/html; } 这样,当发生502或503错误时,nginx会将请求重定向到50x.html页面。我们可以在location指令中指定页面的路径,root指令用于设置页面所在的根目录。此外,error_page指令还可以用于指定单个错误的处理页面,利用在线资源处理指定的错误,甚至可以更改网站响应的状态码等多种设置。通过这些配置,我们可以根据需要自定义nginx错误页面。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [nginx配置文件中的error_page配置详解](https://blog.csdn.net/Teddy_Husky/article/details/121795812)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [nginx自定义错误页](https://blog.csdn.net/qq_41684621/article/details/109424006)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值