Nginx 自定义404、500、502 页面

本文介绍了如何使用Nginx进行反向代理配置,以实现自定义404、500、502等错误状态码的页面。主要步骤包括修改nginx.conf文件启用错误拦截,创建自定义错误页面并将其置于nginx的html文件夹下,最后重启Nginx使配置生效。
摘要由CSDN通过智能技术生成

利用nginx的反向代理来实现 服务器404 和500 等状态码的自定义页面

1.nginx配置文件 nginx.conf 配置开启代理错误拦截 和配置页面  下划线部分 

http {

        ......

    proxy_intercept_errors on;

    fastcgi_intercept_errors on;
    
    server {

         ......


    error_page  404   /notfind.html;
    
    error_page   500 /error.html;
        
    error_page   502 503 504 /error502.html;
    }
}

2.编写自定义页面,将页面放置在nginx路径下的html 文件夹下 页面中用到的图片什么的都放置与此文件夹下

3.重启nginx 配置生效 OK

404页面代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="icon" type="image/x-icon" href="http://zhaixt.info/icon.ico" />
 
<title>404-对不起!您访问的页面不存在</title>
 
<style type="text/css">
 
.head404{
     width:580px; height:234px; margin:50px auto 0 auto; background:url(http://zhaixt.info/head404.png) no-repeat; }
 
.txtbg404{
     width:499px; height:169px; margin:10px auto 0 auto; background:url(http://zhaixt.info/txtbg404.png) no-repeat;}
 
.txtbg404 .txtbox{
     width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值