nginx 配置代理對象的host


nginx配置代理對象,可以修改http的header里面的屬性

方法如下

http {
  server {
  listen       8000;
  server_name localhost;
  location / {
proxy_pass http://springboot;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header Request-Url $request_uri;
      root   /usr/share/nginx/html;
      index index.html index.htm;
  }

}

通過在http->server->proxy_set_header這個屬性來實現

如果要修改代理對象的host則可以 proxy_set_header HOST 【value】;

其中value是你要設置到代理對象里面的具體的值

這個值可以引用nginx的環境變量

$host

  1. 當客戶端通過ip訪問nginx,nginx再將請求轉發到被代理對象時,被代理對象獲取到的host實際上時nginx所在宿主機的ip;

  2. 當客戶端通過域名訪問nginx,被代理對象獲取到的host為客戶端請求的域名

$http_host

  1. 當客戶端通過ip訪問nginx,nginx再將請求轉發到被代理對象時,被代理對象獲取到的host實際上時nginx所在宿主機的ip:port;192.168.137.160:8000

  2. 當客戶端通過域名訪問nginx,被代理對象獲取到的host為客戶端請求的域名;port;如:lgm.com:8000

$proxy_host

這個參數經過測試,跟不配置proxy_set_header效果相同

傳到被代理主機host為proxy_pass配置的域名springboot


免責聲明!

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



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