如何replacenginx中头部的主机variables

我正在尝试replacenginxconfiguration中头部的主机variables,以使some.random.sub.example.net变成net-some.random.sub.example.com 。 我已经尝试了以下内容:

 if ($host ~* "^([^.]+(\.[^.]+)*)\.example.net$"){ set $sub $1; set $host1 "http://net-$sub.example.com"; break; } 

然后在位置指令中,我有:

 location / { proxy_set_header HOST $host1; some conf } 

它并没有工作,但!

编辑

完整configuration:

 server {#http listen 80 default_server; server_name *.example.com; large_client_header_buffers 4 16k; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; if ($host ~* "^([^.]+(\.[^.]+)*)\.example.net$"){ set $sub $1; set $host1 http://cn-$sub.example.com; break; } location / { proxy_pass http://ghs.google.com; proxy_set_header HOST $host1; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-HOST $host; proxy_set_header Proxy-Hostname $scheme://$http_host; proxy_set_header X-Forwarded-Proto https; proxy_pass_request_headers on; proxy_redirect off; proxy_intercept_errors on; proxy_redirect false; } } 

请参阅http proto – 在Host指令中,您不会传递http / https – 仅限服务器名称

好吧,经过大量的实验,我解决了它。

 set $host1 http://cn-$sub.example.com; 

应该 :

 set $host1 cn-$sub.example.com; 

任何解释?