使用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");