使用HAProxy进行IP重定向。

huangapple go评论51阅读模式
英文:

Using HAProxy To Redirect to IP

问题

我们有一种情况,需要根据请求的子域名将流量重定向到具有特定IP的服务器。

例如:

  • 如果请求是https://subdomain01.abc.com,则将请求发送到IP为1.2.3.4的服务器
  • 如果请求是https://subdomain02.abc.com,则将请求发送到IP为1.2.3.10的服务器
  • 如果请求是https://subdomain03.abc.com,则将请求发送到IP为1.2.25.25的服务器

这是否可以使用haProxy实现?我认为这是可能的,但我找不到任何模拟这种情况的好例子。

如果可能的话,我们可以使用的规则数量是否有限制?

感谢任何指向正确方向的提示(或者告诉我这不是haproxy的一个好用例)。

英文:

We have a situation where we need to redirect traffic to a server with a particular IP based on the subdomain of the request.

For example:

Is this possible with haProxy? I'm thinking that this is possible but I can't find any good examples that simulate this.

If this is possible, are there any limits to the number of rules we can use?

Thanks for any pointers in the right direction (or for letting me know that this is not a good use-case for haproxy).

答案1

得分: 2

  • 可以使用HA-Proxy实现吗?是的。
  • 规则有任何限制吗?没有。
  • 应该使用HA-Proxy来实现这个用例吗?我认为不需要。一个更简单的代理就可以完成任务,因为你不需要负载均衡。

以下是您要包含在haproxy.cfg文件中进行测试的内容:

global
    ...

defaults
    ...

frontend https_frontend
    bind *:443
    mode http

    acl subdomain01_acl hdr(host) -i subdomain01.abc.com
    acl subdomain02_acl hdr(host) -i subdomain02.abc.com
    acl subdomain03_acl hdr(host) -i subdomain03.abc.com

    use_backend server1_backend if subdomain01_acl
    use_backend server2_backend if subdomain02_acl
    use_backend server3_backend if subdomain03_acl

backend server1_backend
    mode http
    balance roundrobin
    server server1 1.2.3.4:80

backend server2_backend
    mode http
    balance roundrobin
    server server2 1.2.3.10:80

backend server3_backend
    mode http
    balance roundrobin
    server server3 1.2.25.25:80

(Note: This translation assumes that "HA-Proxy" remains the same in Chinese, as it's a technical term.)

英文:
  • Can it be achieved with HA-Proxy? Yes.
  • Are there any limits on the rules? No.
  • Should you implement this use case with HA-Proxy? I don't think so. A simpler proxy would do the job, since you're not loadbalancing.

This is what you want to include on the haproxy.cfg file if you want to test:

global
    ...

defaults
    ...

frontend https_frontend
    bind *:443
    mode http

    acl subdomain01_acl hdr(host) -i subdomain01.abc.com
    acl subdomain02_acl hdr(host) -i subdomain02.abc.com
    acl subdomain03_acl hdr(host) -i subdomain03.abc.com

    use_backend server1_backend if subdomain01_acl
    use_backend server2_backend if subdomain02_acl
    use_backend server3_backend if subdomain03_acl

backend server1_backend
    mode http
    balance roundrobin
    server server1 1.2.3.4:80

backend server2_backend
    mode http
    balance roundrobin
    server server2 1.2.3.10:80

backend server3_backend
    mode http
    balance roundrobin
    server server3 1.2.25.25:80

huangapple
  • 本文由 发表于 2023年6月16日 09:10:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定