nginx代理后jsp如何获取http协议
1. nginx配置增加返回协议类型(http或https)
location / {proxy_set_header X-Forwarded-Proto $scheme;
}
2. 修改jsp配置
原jsp配置:
<%String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
修改后jsp配置,通过X-Forwarded-Proto获取协议
<%// 获取原始请求的协议String scheme = request.getHeader("X-Forwarded-Proto");if (scheme == null || "".equals(scheme)) {// 如果没有通过代理,则直接从请求对象获取scheme = request.getScheme();}String path = request.getContextPath();String basePath = scheme+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
道阻且长,行则将至,行而不辍,未来可期!
你的关注是我更新的动力!