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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM