今天測試同事在測試接口時遇到了測試環境無法獲取到header中參數的問題,但是本地可以。同時在使用swagger時,測試環境會導致端口丟失,本地不會。
經過反覆查看配置,發現是Nginx引起的。
Nginx做反向代理時默認request的header的那麼中包含’_’時,會自動忽略掉。可以在Nginx的配置文件:nginx.conf 的http部分中添加如下配置:underscores_in_headers on; (默認 underscores_in_headers 爲off)即可解決header參數丟失問題。
在Nginx的配置文件:nginx.conf 的location將 proxy_set_header Host $host;改成 proxy_set_header Host $host:$server_port; 即可解決端口丟失問題。