通过Nginx来拦截系统访问出现的404问题。
来源:系统割接,没有在系统内部没有兼容旧版本的链接,导致旧版本的访问链接全部失效,出现tomcat 404 提示。
处理方案:
1、系统内部进行兼容处理,规避404问题。
2、Nginx拦截所有404,并指向对应的界面。
因是单机线上系统,不便在系统中加入逻辑处理,现采用第二种处理方案。
处理遇到问题:
配置 error_page 404 /404.html 无效无法监听到404请求状态。
处理方案:
添加 proxy_intercept_errors on; 配置,因采用代理模式, 所以404状态在普通模式下监听不到,需要先开启此配置,error_page 404 /404.html才有作用
配置代码:
http {
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on; # 单独配置此项无效
proxy_intercept_errors on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent --- $host --- "$http_referer" '
'