前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >Nginx结构全解析(35)

Nginx结构全解析(35)

原创
作者头像
陈不成i
修改2021-05-12 18:04:33
修改2021-05-12 18:04:33
2490
举报
文章被收录于专栏:ops技术分享ops技术分享

6.2 反向代理的错误页面

如果后台Tomcat处理报错抛出404,想把这个状态叫Nginx反馈给客户端或者重定向到某个连接,配置如下:

  1. upstream www {
  2. server 192.168.1.201:8080 weight=20 max_fails=2 fail_timeout=30s
  3. ip_hash;
  4. }
  5. server {
  6. listen 80;
  7. server_name www.test.com;
  8. root /var/www/test;
  9. index index.html;
  10. location / {
  11. if($request_uri ~* '^/$') {
  12. rewrite .* http://www.test2.com/index.html redirect;
  13. }
  14. # 关键参数:这个变量开启后,我们才能自定义错误页面,当后端返回404,nginx拦截错误,定义错误页面
  15. proxy_intercept_errors on;
  16. proxy_pass http://www;
  17. proxy_set_header HOST $host;
  18. }
  19. error_page 404 /404.html;
  20. location = /404.html {
  21. root /usr/share/nginx/html;
  22. }
  23. }

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 6.2 反向代理的错误页面
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档