WEB服务与NGINX(7)-实现自定义错误页面
2021/6/20 7:26:54
本文主要是介绍WEB服务与NGINX(7)-实现自定义错误页面,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 自定义错误页面
-
error_page code ... [=[response]] uri;
定义错误页,以指定的响应状态码进行响应,此指令由ngx_http_index_module模块提供
支持环境:http, server, location, if in location
#1.修改nginx的配置文件如下,定义错误页,把500 502 503 504 404这些状态码转换为200状态码,并定义错误页面。 [root@nginx01 ~]# vim /etc/nginx/conf.d/virtualhost.conf server { listen 80; server_name www.nginx01.com; location / { root /data/nginx/html/web1; index index.html; } error_page 500 502 503 504 404 =200 /errorpage.html; location = /errorpage.html { root /data/nginx/html/web1/errorpage/; } } #2.重启nginx服务 [root@nginx01 web1]# systemctl reload nginx.service #3.在web1下新建目录errorpage和文件errorpage/errorpage.html [root@nginx01 web1]# ll errorpage/ total 4 -rw-r--r-- 1 root root 31 Jun 15 23:30 errorpage.html [root@nginx01 web1]# cat errorpage/errorpage.html our system is being maintained #4.使用客户端访问一个不存在的页面,能正常返回自定义的错误页面,状态码变为200 [root@xuzhichao ~]# curl http://www.nginx01.com/abc our system is being maintained [root@xuzhichao ~]# curl -I http://www.nginx01.com/abc HTTP/1.1 200 OK Server: nginx/1.20.1 Date: Tue, 15 Jun 2021 15:36:27 GMT Content-Type: text/html Content-Length: 31 Last-Modified: Tue, 15 Jun 2021 15:30:38 GMT Connection: keep-alive ETag: "60c8c79e-1f" Accept-Ranges: bytes
这篇关于WEB服务与NGINX(7)-实现自定义错误页面的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29fail2ban nginx
- 2024-03-18install nginx proxy manager
- 2024-01-2444从零开始用Rust编写nginx,命令行参数的设计与解析及说明
- 2024-01-22比Nginx更好用的Gateway!
- 2024-01-17nginx daemon off
- 2023-12-30Nginx Vhost Traffic Status 是什么意思-icode9专业技术文章分享
- 2023-12-26使用nginx搭建creates.io镜像(稀疏索引)
- 2023-11-18centos7编译安装Nginx教程。
- 2023-11-02nginx启动命令和停止命令
- 2023-10-25Centos7系统Nginx负载均衡如何安装和配置?