在nginx转发时保留原始域名( keep the Host header via nginx proxy_pass )

访问量: 2755

最近的子项目越来越多,但是只有一个域名, 在做了nginx的跳转之后, 发现原来的域名会丢失,取代出现的是IP。

(with the growth of the sub-systems of my current project, there is a problem occurred: the origin domain name disappeared and it is replaced by the ip addresses , which is not liked by my workmates.  ) 

所以我们要保留原始域名,这货也叫 Host header.  (so the solution is to keep the origin domain name . aka host Header.  )

solution is : proxy_set_header Host $http_host;

    server {
        listen 80; 
        # this is the key !!!!! 
        proxy_set_header Host $host;
        location /client/pids {
            proxy_pass http://10.103.13.103:3200/client/pids;
        }
        location /interface/client/pids {
            proxy_pass http://10.103.13.103:3200/interface/client/pids;
        }
        ......

refer to: https://www.simplicidade.org/notes/archives/2011/02/nginx_proxy_host_header.html and http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header

订阅/RSS Feed

Subscribe

分类/category