簡體   English   中英

Nginx 中的 $http_host:$proxy_port 和 $host:$server_port 有什么區別

[英]What's the difference of $http_host:$proxy_port and $host:$server_port in Nginx

The company that I work for, uses Nginx for Reverse Proxy and Load Balancer, so I just add an another block to nginx.conf file as shown below for the new service, when requesting Nginx server with curl http://10.11.12.15:8080/api Nginx 返回 400 Bad Request,但是在更改此配置后proxy_set_header Host $http_host:$proxy_port; proxy_set_header Host $host:$server_port; 解決了錯誤請求問題。 但我不明白這一點。

我已經閱讀了這個答案What's the difference of $host and $http_host in Nginx and Practical difference of $http_host and $host

但這種情況沒有明確的答案。 這個標題有什么區別?

proxy_set_header Host $http_host:$proxy_port;

proxy_set_header Host $host:$server_port;

用過這個塊;

 upstream web-service {

    server 10.11.12.13:8080;
    server 10.11.12.14:8080 backup;
  }
  server {

    listen 8080;
    server_name myHost 10.11.12.15;
    location / {

      proxy_pass http://web-service;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $http_host:$proxy_port;  # Throw HTTP 400 Bad Request
  #   proxy_set_header Host $host:$server_port;      # Working solution
    }
  }

$http_host非默認時已經包含端口。 因此,如果您再次嘗試添加端口,則會出錯。 $host不包括端口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM