Nginx采坑日记(后台响应ResponseEntity时,Nginx将部分数据过滤)

 

执行流程:

问题描述:

  后台响应ResponseEntity时,Nginx将部分数据过滤了,导致Vue提示如下图,但是实际上已经代理成功并返回数据了。

原因:

官网说明:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version

By default, nginx does not pass the header fields “Date”, “Server”, “X-Pad”, and “X-Accel-...” from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed. If, on the contrary, the passing of fields needs to be permitted, the proxy_pass_header directive can be used.

默认情况下,nginx不会将头字段“Date”、“Server”、“X-Pad”和“X-Accel-…”从代理服务器的响应传递到客户端。proxy_hide_header指令设置不会传递的其他字段。相反,如果需要允许字段的传递,则可以使用proxy_pass_header指令。

解决办法:

proxy_http_version 默认为1.0,将 proxy_http_version 设置 1.1; 即可

例如:
location /api/ {
            proxy_http_version 1.1;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Nginx-Proxy true;
            proxy_set_header Connection "";
            proxy_pass  http://localhost:8099;
        }
文章灵感来自:https://blog.csdn.net/sc9018181134/article/details/82055225
原文地址:https://www.cnblogs.com/damaoa/p/13223921.html