您的位置:首页 > 运维架构 > Nginx

nginx 自定义404 500 错误页面

2018-02-17 20:33 537 查看
转:https://www.cnblogs.com/paul8339/p/7389422.html
第二种:反向代理的错误页面如果后台Tomcat处理报错抛出404,想把这个状态叫Nginx反馈给客户端或者重定向到某个连接,配置如下:
upstream www {server 192.168.1.201:7777  weight=20 max_fails=2 fail_timeout=30s;ip_hash;}server {listen       80;server_name www.test.com;root   /var/www/test;index  index.html index.htm; location / {if ($request_uri ~* ‘^/$’) {rewrite .*   http://www.test.com/index.html redirect;}# 关键参数:这个变量开启后,我们才能自定义错误页面,当后端返回404,nginx拦截错误定义错误页面proxy_intercept_errors on;proxy_pass      http://www;proxy_set_header HOST   $host;proxy_set_header X-Real-IP      $remote_addr;proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for;}error_page    404  /404.html;location = /404.html {root   /usr/share/nginx/html;}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: