nginx+tomcat集群发生404时转发到可用的tomcat
在服务器部署的时候,可能会发生404错误,这时候 可以将请求转发到正常的tomcat
可以实现无感升级和不停机部署
转发了
http_404 http_500 http_502 http_503 http_504
#设定负载均衡的服务器列表 upstream minds { #weight为服务器权重,权值越高被分配到的几率越大,max_fails最大超时次数,fail_timeout服务器代理被挂起的时间 #ip_hash; server 192.168.2.117:8080 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:8080 weight=99 max_fails=2 fail_timeout=30s; } server { listen 8020; server_name 127.5.5.5; location / { root html; index index.html index.htm; proxy_pass http://minds; #proxy_redirect off; # 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 1s; proxy_send_timeout 30s; proxy_read_timeout 3s; proxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_503 http_504; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
原理参考:
http://saiyaren.iteye.com/blog/1914865
https://bbs.csdn.net/topics/392283483?page=1
http://blog.sina.com.cn/s/blog_8f2ef1220102vpsg.html
https://blog.csdn.net/qq_38377190/article/details/80269296