nginx的error_page配置选项
1.语法
句法: error_page code ... [=[response]] uri; 默认: - 内容: http,server,location,if in location
2.跳转其他网站
[root@web01 /etc/nginx/conf.d]# vim linux.web.com.conf server { listen 80; server_name linux.web.com; location / { root /code/web; index index.html; error_page 403 404 http://www.baidu.com; } } #error_page配置的是http这种的网络地址 #访问linux.web.com报错403、404跳转到百度页面
3.跳转本地文件
[root@web01 /etc/nginx/conf.d]# vim linux.web.com.conf 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]# vim linux.web.com.conf 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]# vim /etc/nginx/conf.d/wordpress.conf 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; } }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论