如果后端真是的服務器設置有類似防盜鏈或者根據http請求頭中的host字段來進行路由或判斷功能的話
,如果反向代理層的nginx不重寫請求頭中的host字段,將會導致請求失敗,報400錯誤,
解決辦法:
location中設置
proxy_set_header Host $http_host;
[root@nignx ~]#vim /usr/local/nginx/conf/nginx.conf
server { listen 80; server_name localhost; charset utf-8; access_log logs/host.access.log main; location / { root html; index index.html index.htm; proxy_set_header Host $http_host; //此處要添加host頭,將頭信息返回服務器 }
