location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $target 'unknown';
if ( $http_cookie ~* "target=(.*)$")
{
set $target $1;
}
if ($domain ~ "target1")
{
proxy_pass http://target1;
break;
}
if ($domain ~ "target2")
{
proxy_pass http://target2;
break;
}
proxy_pass http://dfeualt;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $target 'unknown';
if ( $http_cookie ~* "target=(.*)$")
{
set $target $1;
}
if ($domain ~ "target1")
{
proxy_pass http://target1;
break;
}
if ($domain ~ "target2")
{
proxy_pass http://target2;
break;
}
proxy_pass http://dfeualt;
}
本文详细介绍了Nginx中的反向代理配置方法,包括如何设置头部信息、使用cookie进行目标选择以及根据不同域名指向不同的后端服务。通过具体的配置示例,读者可以了解到如何实现灵活的流量调度。
1433

被折叠的 条评论
为什么被折叠?



