006-nginx.conf详解-error_page 使用
一、概述
nginx指令error_page的作用是当发生错误的时候能够显示一个预定义的uri
1.1、使用步骤
更改nginx.conf在http定义区域加入: proxy_intercept_errors或者fastcgi_intercept_errors
fastcgi_intercept_errors on;#默认off
如果没这句的不管是error_page 还是nginx自带的404跳转都不能正常显示(访问不存在的页面时可能会显示“No input file specified.”)
- 默认: fastcgi_intercept_errors off
- 添加位置: http, server, location, location 中的if字段
- 默认情况下,nginx不支持自定义404错误页面,只有这个指令被设置为on,nginx才支持将404错误重定向
1.2、配置全局错误【可不配置】
可以在http下添加
error_page = http://www.github.com/404.html;
1.3、针对http中server具体配置error_page
更改nginx.conf,在server 区域加入: error_page 404 /404.html 或者 error_page 404 =http://www.xxx.com/404.html
1.3.1、方式一、本地文件-直接读取本地物理文件
error_page /.html;
location =/.html {
root /export/servers/nginx/html;
}
实际上产生了一个内部跳转(internal redirect),当访问出现上述错误码的时候就能返回404.html中的内容,这里需要注意是否可以找到404.html页面,所以加了个location保证找到你自定义的404页面。
1.3.2、方式二、指向具体url
error_page http://www.xxx.com/404.html
1.3.3、方式三、设置named location,然后在里边做对应的处理。
error_page @jump_to_error;
location @jump_to_error {
proxy_pass http://backend;
}
同时error_page在一次请求中只能响应一次,对应的nginx有另外一个配置可以控制这个选项:recursive_error_pages
默认为false,作用是控制error_page能否在一次请求中触发多次。
1.4、重定义响应码【使用等号】
1、自己定义返回状态码【等号后面追加响应码 如 =200】
error_page 400 401 402 403 404 405 408 410 412 413 414 415 500 501 502 503 504 506 =200 /404.html;
location =/404.html {
root /export/servers/nginx/html;
}
这样用户访问产生上述响应码的时候给用户的返回状态是200,内容是404.html。
2、使用要访问页状态码【等号后面不写响应码 如 =】
error_page = /.html;
location =/.html {
root /export/servers/nginx/html;
}
二、压缩
gzip压缩作用:将响应报⽂发送⾄客户端之前可以启⽤压缩功能,这能够有效地节约带宽,并提⾼响应⾄客户端的速度,压缩会消耗nginx的cpu性能
gzip压缩可以配置http,server和location模块下
0.压缩语法
location ~ .*\.(jpg|gif|png|bmp)$ //~区分大小写, 匹配任意字符开头以.jpg或.bmp结尾,注意这里的jgp等类型需要使用gzip_types调用
gzip on; //开启gzip压缩
gzip_http_version 1.1 //压缩协议版本
gzip_comp_level 3; //压缩比率
gzip_types //压缩类型,根据/usr/local/nginx/conf/mime.types中定义;
示例:
location ~ .*\.(jpg|gif|png|bmp)$ {
gzip on;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;
}
}
006-nginx.conf详解-error_page 使用的更多相关文章
- 004-mac上安装以及Nginx 配置文件nginx.conf详解
1.mac上nginx安装 安装brew:go-001-环境部署,IDEA插件 安装nginx: brew search nginx brew install nginx 当然也可以编译安装 安装完以 ...
- Nginx 配置文件 nginx.conf 详解
Nginx的配置文件nginx.conf配置详解如下: user nginx nginx; #Nginx用户及组:用户 组.window下不指定 worker_processes 8; #工作进程:数 ...
- Nginx安装及配置文件nginx.conf详解
1.安装Nginx 在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcre-devel和zlib-devel软件库. 下面是Nginx安装过程: wget http ...
- Nginx安装与配置文件nginx.conf详解
引用“http://ixdba.blog.51cto.com/2895551/790611” 1.安装Nginx在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcr ...
- nginx.conf详解
##定义nginx运行的用户各用户组user nginx nginx; ##nginx进程数,建议设置与cpu核心数一致worker_processes 1; #为每个进程分配CPU的工作内核 wor ...
- nginx作为web服务以及nginx.conf详解
Nginx系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.nginx简介 nginx是一个优秀的web服务程序.反向代理程序.它采用非 ...
- Nginx配置文件nginx.conf详解
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...
- Nginx配置文件nginx.conf详解(转)
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...
- Nginx 中 nginx.conf 详解
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...
随机推荐
- python之栈与队列
这个在官网中list支持,有实现. 补充一下栈,队列的特性: 1.栈(stacks)是一种只能通过访问其一端来实现数据存储与检索的线性数据结构,具有后进先出(last in first out,LIF ...
- 【转】STM32利用FATFS读写数组
因为存为TXT可以实现,但是读取TXT里边的数据总是不尽如人意,所以,最终存为bin文件了. 先摘几个观点: http://www.openedv.com/posts/list/36712.htm “ ...
- 关于ping github.com超时的解决办法
今天在使用git的时候执行将本地分支推送到远程分支的push操作时(同时为远程库创建和本地分支同名的分支),遇到了超时的错误,经过查询全网各位大牛的操作这里给出有效解决方式 进入C:\Windows\ ...
- 2019年杭电多校第一场 1002题Operation(HDU6579+线性基)
题目链接 传送门 题意 初始时有\(n\)个数,现在有\(q\)次操作: 查询\([l,r]\)内选择一些数使得异或和最大: 在末尾加入一个数. 题目强制在线. 思路 对于\(i\)我们记录\([1, ...
- font-awesome图标显示问题解决方案
font-awesome一个很强大的字体图标库.下载链接:http://fontawesome.dashgame.com/刚开始使用font-awesome的新手往往容易只引入一个css文件,这样就会 ...
- flask实战-个人博客-程序骨架、创建数据库模型、临接列表关系 --
编写程序骨架 personalBlog的功能主要分为三部分:博客前台.用户认证.博客后台,其中包含的功能点如下图所示: 数据库 personalBlog一共需要使用四张表,分别存储管理员(Admin) ...
- php解析xml的几种方式
php提供几种解析xml的类或方法,包括:Xml parser. SimpleXML,.XMLReader,.DOMDocument. XML Expat Parser: XML Parser使用Ex ...
- Spring Boot + Mybatis 配置多数据源
Spring Boot + Mybatis 配置多数据源 Mybatis拦截器,字段名大写转小写 package com.sgcc.tysj.s.common.mybatis; import java ...
- react native iOS真机调试-联网问题与js严格模式
rn:strict mode does not allow function declarations in a lexically nested statement https://blog.csd ...
- Vsftpd 2.2.x安装和配置--centos7前的版本
Vsftpd 2.2.x安装和配置--centos7前的版本 原文链接:https://my.oschina.net/loubobooo/blog/1633367 1. 关闭防火墙和Selinux L ...