gpt4 book ai didi

networking - 在 haproxy 后端使用域而不是 IP

转载 作者:行者123 更新时间:2023-12-01 02:03:51 25 4
gpt4 key购买 nike

我有 2 个虚拟主机

app.example.com:80 在 IP 地址 xxx.xxx.xxx.xxx
app2.example.com:80 在 IP 地址 yyy.yyy.yyy.yyy
我的haproxy ipaddress 是sss.sss.sss.sss
这是 haproxy 配置:

global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy

defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 10000

frontend www-http
mode http
bind *:80
default_backend appname
stats enable
stats uri /haproxy?stats
stats auth admin:password
stats show-node

backend appname
balance roundrobin
option httpclose
option forwardfor
server lamp1 app.example.com:80 check
server lamp2 app2.example.com:80 check

当尝试使用 haproxy ipaddress 访问时,Web 浏览器返回 xampp 仪表板而不是后端内容。

如何让 haproxy 重定向到后端内容?

最佳答案

我确实相信该功能现在在 1.6 中可用,
http://blog.haproxy.com/2015/10/14/whats-new-in-haproxy-1-6/

您配置的内容将简单地将这些请求负载均衡到实例:

server lamp1 app.example.com:80 check
server lamp2 app2.example.com:80 check

如果它们是 2 个单独的应用程序,请尝试:
frontend www-http
mode http
bind sss.sss.sss.sss:80
stats enable
stats uri /haproxy?stats
stats auth admin:password
stats show-node

acl app01 hdr(Host) -i app.example.com
acl app02 hdr(Host) -i app02.example.com

use_backend app01 if app01
use_backend app02 if app02

backend app01
balance roundrobin
option httpclose
option forwardfor
server lamp1 xxx.xxx.xxx.xxx:80 check

backend app02
balance roundrobin
option httpclose
option forwardfor
server lamp2 yyy.yyy.yyy.yyy:80 check

如果您现在使用 app.example.com 访问您的 haproxy,您将被转发到 lamp1,而 app2.example.com 将带您到 lamp2

如果您想将所有内容转发到 ip 到后端并且不关心额外的匹配和映射,那么 id 使用直接监听,而不是前端:
 listen SOMENAME sss.sss.sss.sss:80
balance leastconn
mode http
server lamp1 xxx.xxx.xxx.xxx:80
server lamp2 yyy.yyy.yyy.yyy:80

关于networking - 在 haproxy 后端使用域而不是 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com