特別提示:本人博客部分有參考網絡其他博客,但均是本人親手編寫過並驗證通過。如發現博客有錯誤,請及時提出以免誤導其他人,謝謝!歡迎轉載,但記得標明文章出處:
http://www.cnblogs.com/mao2080/
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 }
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/