我是 N00b,我正在尝试为 HAproxy 创建一个配置文件,但是我对这个主题的理解有些问题。
因此,在这个例子中,我希望能够在访问时加载 wordpresshttp://VMip当我使用http://VMip/phpmyadmin能够使用 phpMyAdmin 创建数据库/用户等。
下面是我的 HAproxy 配置文件。
如果您需要更多信息,我很乐意提供。提前谢谢您。
global
log fd@2 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
stats socket /var/lib/haproxy/stats expose-fd listeners
master-worker
resolvers docker
nameserver dns1 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold other 10s
hold refused 10s
hold nx 10s
hold timeout 10s
hold valid 10s
hold obsolete 10s
defaults
timeout connect 10s
timeout client 30s
timeout server 30s
log global
mode http
option httplog
frontend www
bind *:80
use_backend stat if { path -i /my-stats }
use_backend php if { path -i /phpmyadmin }
default_backend wordpress
backend php
# reqrep ^([^\ :])\ /phpmyadmin/(.) \1\ /\2
balance roundrobin
server php phpmyadmin:80 check resolvers docker init-addr libc,none
backend wordpress
balance roundrobin
server wordpress wordp:80 check resolvers docker init-addr libc,none
backend stat
stats enable
stats uri /my-stats
stats refresh 15s
stats show-legends
stats show-node
答案1
在文档中找到了解决方案 https://docs.phpmyadmin.net/en/latest/setup.html并应用于以下配置,其工作符合预期:
global
log fd@2 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
stats socket /var/lib/haproxy/stats expose-fd listeners
master-worker
resolvers docker
nameserver dns1 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold other 10s
hold refused 10s
hold nx 10s
hold timeout 10s
hold valid 10s
hold obsolete 10s
defaults
timeout connect 10s
timeout client 30s
timeout server 30s
log global
mode http
option httplog
frontend http
bind *:80
use_backend stat if { path -i /my-stats }
option forwardfor
option http-server-close
acl phpmyadmin path_dir /phpmyadmin
use_backend php if phpmyadmin
default_backend wordpress
backend php
mode http
balance source
hash-type consistent
reqirep ^(GET|POST|HEAD)\ /phpmyadmin/(.*) \1\ /\2
acl hdr_location res.hdr(Location) -m found
rspirep ^Location:\ (http?://phpmyadmin.local(:[0-9]+)?)?(/.*) Location:\ // if hdr_location
server-template php- 7 phpmyadmin:80 cookie php check resolvers docker init-addr libc,none
backend wordpress
balance source
hash-type consistent
server-template wordp- 7 wordp:80 cookie wordpress check resolvers docker init-addr libc,none
backend stat
stats enable
stats uri /my-stats
stats refresh 15s
stats show-legends
stats show-node