nginx设置错误页面

当访问服务器遇到500 502 503 504 等错误时跳转到错误页面:

cat /usr/local/nginx/conf/conf.d/jingxiang.conf
        error_page   500 502 503 504 /50x.html;
        location = /50x.html {
                root   html;  # 这里指向的是 Nginx 的默认 html 目录
        }


cat /usr/local/nginx/html/50x.html
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>An error occurred.</h1>
<p>Sorry, the page you are looking for is currently unavailable.<br/>
Please try again later.</p>
<p>If you are the system administrator of this resource then you should check
the error log for details.</p>
<p><em>Faithfully yours, nginx.</em></p>
</body>
</html>

20250819160341

posted @ 2025-08-14 19:17  阿峰博客站  阅读(9)  评论(0)    收藏  举报