Nginx reverse proxy settings header

Special Note: I have a blog section reference other blog networks, but are written over and I personally verified. Blog found an error, please put forward so as not to mislead other people, thank you! Welcome to reprint, but remember to indicate the source of the article: http://www.cnblogs.com/mao2080/

1, the problem

  In doing before and after the end of the FBI, the need to increase header for different url.

2, the code fragment

2.1Nginx Configuration

 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 Interface
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/

Guess you like

Origin www.cnblogs.com/mao2080/p/11734424.html