在IPINX中将IP重定向到主机名

时间:2013-07-29 08:53:30

标签: redirect url-rewriting nginx proxy ip

我想使用重写指令将我网站的每个IP地址重定向到该网站的主机名,然后使用NGINX中的 proxy_pass 指令访问该网站

 proxy_pass http://host/name ;

使用NGINX作为代理可以工作,但我无法更改我的脚本以重写地址并同时代理我的请求。我试图使用Rewrite指令,但我找不到合适的语法。

1 个答案:

答案 0 :(得分:0)

使用rewrite指令更改主机将导致重定向。这意味着客户端需要使用新主机发布另一个请求,然后,您可以proxy_pass此请求。在这种情况下,客户端(例如,浏览器)中的URL将会更改,例如“http://*.*.*.*:port/uri?request_string” - > 'http://host/uri?request_string'。

通常,我们使用rewrite指令来更改将被proxy_passed的请求的URI。如果要使用proxy_set_header更改主机。一个例子:

location ~* "^/maishenme/(knowse|knowdetail|iget|ilist|initem|i?compare)(.*)?$" {
        rewrite "^/maishenme/(.*)?$" /$1 break;
        proxy_pass http://***.xxx.com;
        proxy_set_header Host "internal.xxx.com";
        break;
}

在这种情况下,从客户端,url不会更改,但对于后端服务器,您可以打印主机字段并将其更改为“internal.xxx.com”

相关问题