1、问题所在
在做前后端联调时,需要对不同的url增加header。
2、代码片段
2.1Nginx配置
1 server { 2 listen 80; 3 server_name test.com; 4 5 location /api/ { 6 proxy_pass http://localhost:8081/api/; 7 proxy_set_header tenant 1006; 8 } 9 10 location / { 11 root D:\web; 12 index index.html; 13 } 14 15 }2.2Java接口
1 @RequestMapping(value = "/checkHeader", method = {RequestMethod.POST}, consumes = MediaType.APPLICATION_JSON_VALUE) 2 @ResponseBody 3 public String checkHeader(HttpServletRequest request) throws IOException { 4 String tenant = request.getHeader("tenant"); 5 System.out.println("tenant:"+tenant); 6 return "Success"; 7 }
3、执行效果
tenant:1006
4、参考网站
https://www.iyunw.cn/archives/nginx-fan-xiang-dai-li-tian-jia-zi-ding-yi-headers/