1.语法
句法: error_page code ... [=[response]] uri;
默认: -
内容: http,server,location,if in location
2.跳转其他网站
[root@web01 /etc/nginx/conf.d]
server {
listen 80;
server_name linux.web.com;
location / {
root /code/web;
index index.html;
error_page 403 404 http://www.baidu.com;
}
}
3.跳转本地文件
[root@web01 /etc/nginx/conf.d]
server {
listen 80;
server_name linux.web.com;
location / {
root /code/web;
index index.html;
error_page 403 404 /404.jpg;
}
}
4.访问php文件错误页面跳转
[root@web01 /etc/nginx/conf.d]
server {
listen 80;
server_name linux.web.com;
root /code/web;
index index.php;
error_page 404 403 /404.html;
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if (!-e $request_filename) {
rewrite (.*) http://linux.web.com/404.jpg;
}
}
}
5.完整配置
[root@zzc /blog/wordpress]
server {
listen 80;
server_name localhost;
root /blog/wordpress;
location / {
index index.php;
error_page 403 404 /404.jpg;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if (!-e $request_filename){
rewrite (.*) http://zzcblog.top/404.jpg;
}
}
location ~* \.(jpg|png)$ {
root /blog/wordpress;
error_page 403 404 /404.jpg;
}
}