使用zuul作为网关作为反向代理,由于后端的一个服务限制了request中的host头部信息和服务器一致,但是因为在zuul的配置中设置了传递原始host信息,导致无法正常访问。所以需要在zuul网关的配置中设置不传递host信息,可以在全局中设置,也可以在具体的自定义路由中设置
传递原始请求地址的host的配置,在yml文件中配置:
zuul: sensitive-headers: add-host-header: true
现在设置不传递原始请求地址的host,配置如下:
zuul: sensitive-headers: set-cookie,cookie,connection,content-length,content-encoding,server,transfer-encoding,x-application-context #add-host-header: true
也可以在设置add-host-header:true的情况,设置不传递敏感头信息
zuul: sensitive-headers: host #set-cookie,cookie,host,connection,content-length,content-encoding,server,transfer-encoding,x-application-context add-host-header: true
需要注意的是,如果需要传递host,即使在sensitive-headers中不注明host,但是如果不写add-host-header:true,原始的host信息还是不会向下游服务传递的
host信息,通过zuul的addZuulRequestHeader方式无法更改,
referer信息,通过zuul的addZuulRequestHeader方式可以更改
ctx.addZuulRequestHeader("referer","dd");