第一步,编辑 /usr/local/nginx/conf/nginx.conf 文件,在http区域添加下面的代码;
实现代码如下:
fastcgi_intercept_errors on;

第二步,编辑你需要添加404页面的网站的conf文件,对应在 usr/local/nginx/conf/vhost/XXXX.com.conf,在server区域添加代码;
实现代码如下:
error_page 404 = /404.html;
第三步,重启 LNMP;
实现代码如下:
/root/lnmp restart
总结,我们可以通过 /usr/local/nginx/sbin/nginx -t 来测试返回状态是否正确。
实现代码如下:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
如果是上述返回状态,就是正确的。
以上就是【LNMP系列教程之 设置404错误页面】的全部内容了,欢迎留言评论进行交流!