免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 7223 | 回复: 24
打印 上一主题 下一主题

haproxy配置求助 [复制链接]

论坛徽章:
1
黑曼巴
日期:2017-11-27 16:06:48
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-11-27 18:38 |只看该作者 |倒序浏览
本帖最后由 shouyu924 于 2016-11-28 15:33 编辑

当前网站http转https(部分)定义了80与443监听,需要http与https共存

acl http_w hdr_reg(host) -i   ^www.abc.com
acl http_m hdr_reg(host) -i   ^m.abc.com
use_backend w if http_w
use_backend  m if http_m
backend w
10.10.10.1
10.10.10.2
backend m
10.10.10.1
10.10.10.2


acl http_ws hdr_reg(host) -i   ^www.abc.com
acl http_ms  hdr_reg(host) -i  ^m.abc.com
use_backend ws if http_ws
use_backend  ms if http_ms
backend ws
10.10.10.1
10.10.10.2
backend ms
10.10.10.1
10.10.10.2

为什么这样写不行的啊,请大神帮忙啊




论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2016-11-28 12:56 |只看该作者
回复 1# shouyu924

出现什么问题了? 感觉这俩配置只是 acl 和 backend 的命令不一样。

论坛徽章:
1
黑曼巴
日期:2017-11-27 16:06:48
3 [报告]
发表于 2016-11-28 14:45 |只看该作者
回复 2# Godbach
是的.我希望浏览器访问进来,如果用http访问,返回80后台给前端请求,如果https访问,返回443后台给前端请求

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
4 [报告]
发表于 2016-11-28 15:13 |只看该作者
回复 3# shouyu924

你这个地方是要 匹配 host 吧。建议你用 hdr() 关键字来比较:

acl host1 hdr(host) -i www.abc.com
acl host2 hdr(host) -i m.abc.com

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
5 [报告]
发表于 2016-11-28 15:22 |只看该作者
回复 1# shouyu924

ACL 的语法如下:
acl <aclname> <criterion> [flags] [operator] <value> ...

你确定你那么写 ACL,HAProxy 可以正常解析吗?


论坛徽章:
1
黑曼巴
日期:2017-11-27 16:06:48
6 [报告]
发表于 2016-11-28 15:31 |只看该作者
本帖最后由 shouyu924 于 2016-11-28 15:33 编辑

我是按照产线的配置写的,产线的是这么用的
acl url_m   hdr_reg(host) -i    ^m.abc.com

论坛徽章:
1
黑曼巴
日期:2017-11-27 16:06:48
7 [报告]
发表于 2016-11-28 15:37 |只看该作者
回复 5# Godbach

主题写少写了hdr_reg(host) -i   ..,我现在卡在同一个域名两种方式,http,https.如何写正则,如果用hdr_reg(host) -i  ^ 形式,这样请求只会在最开始定义的80端口即便我用https

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
8 [报告]
发表于 2016-11-28 15:49 |只看该作者
回复 7# shouyu924

host 匹配不建议用正则,直接精确匹配吧。
此外,没看到你的配置中所谓的 80 443 共存的逻辑。你能贴一下你实际的配置吗

论坛徽章:
1
黑曼巴
日期:2017-11-27 16:06:48
9 [报告]
发表于 2016-11-28 16:14 |只看该作者
回复 8# Godbach


global

    log         127.0.0.1 local3
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     8000
    user        haproxy
    group       haproxy
    daemon
    #debug
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats level admin


defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option                     http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           1m
    maxconn                 8000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:80
--------------------------------------------


acl url_www hdr_reg(host) -i    ^www.liness.com
acl url_hatlineapi hdr_reg(host) -i  ^hat.api.liness.cn


use_backend               backendall if url_www
use_backend               backendall if url_hatlineapi


backend backendall
    mode        http
    balance     roundrobin

    option      forwardfor
    server      10.28.27.92:80 cookie  weight 1   check
    server      10.21.41.229:80 cookie  weight 1  check



下面是我新添加的配置

frontend www-https
bind *:443
mode tcp


acl url_wwws hdr(host) -i    www.liness.com
acl url_hatlineapis hdr(host) -i  hat.api.liness.cn



use_backend               backendalls if url_wwws
use_backend               backendalls if url_hatlineapis

backend backendalls
    server      10.28.27.92:443 cookie  weight 1   check
    server      10.21.41.229:443 cookie  weight 1  check

论坛徽章:
1
黑曼巴
日期:2017-11-27 16:06:48
10 [报告]
发表于 2016-11-28 16:15 |只看该作者
回复 8# Godbach


global

    log         127.0.0.1 local3
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     8000
    user        haproxy
    group       haproxy
    daemon
    #debug
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats level admin


defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option                     http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           1m
    maxconn                 8000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:80
--------------------------------------------


acl url_www hdr_reg(host) -i    ^www.liness.com
acl url_hatlineapi hdr_reg(host) -i  ^hat.api.liness.cn


use_backend               backendall if url_www
use_backend               backendall if url_hatlineapi


backend backendall
    mode        http
    balance     roundrobin
    #balance    source
    #balance    static-rr
    #cookie      SERVERID insert
    #option      httpclose
    option      forwardfor
    server      10.28.27.92:80 cookie  weight 1   check
    server      10.21.41.229:80 cookie  weight 1  check


------------------------------------
以下是我的配置.
frontend www-https
bind *:443
mode tcp


acl url_wwws hdr(host) -i    www.liness.com
acl url_hatlineapis hdr(host) -i  hat.api.liness.cn



use_backend               backendalls if url_wwws
use_backend               backendalls if url_hatlineapis

backend backendalls
    server      10.28.27.92:443 cookie  weight 1   check
    server      10.21.41.229:443 cookie  weight 1  check

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP