1、写好准备用作错误页的HTML页面
2、将错误页面放到nginx的html路径:即nginx路径/html
3、nginx路径下的conf文件夹下的nginx.conf配置文件的http模块增加一行配置,用于表示打开当遇到错误时,允许打开错误页
proxy_intercept_errors on;
4、nginx.conf文件中指定域名所对应的server_name中增加错误页面配置
error_page 404 /404.html;
location = /404.html {
root /nginx/html;
}
error_page 500 /500.html;
location = /500.html {
root /opt/web/nginx/html;
}
5、当访问域名不存在的网页或者资源时,系统nginx会根据错误代码404或者500,自动跳转到指定页面