HAProxy advanced configuration options -haproxy predefined (built-in) acl Use Cases

         HAProxy advanced configuration options -haproxy predefined (built-in) acl Use Cases

                                       Author: Yin Zhengjie

Copyright: original works, declined to reprint! Otherwise held liable.

 

 

.Haproxy a built-in ACL Overview

Bloggers Recommended reading:
  http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#7.4

 

II. Use the built-acl real case

1>. Backend server installation and data preparation

  The process is relatively simple, you can refer to my previous note: HTTPS: // www.cnblogs.com/yinzhengjie/p/12153240.html

2>. Haproxy editing configuration files

[[email protected] ~]# cat /etc/haproxy/haproxy.cfg
global
    maxconn 100000
    chroot /yinzhengjie/softwares/haproxy
    stats socket /yinzhengjie/softwares/haproxy/haproxy.sock mode 600 level admin
    user haproxy
    group haproxy
    daemon
    nbproc 2
    cpu-map 1 0
    cpu-map 2 1
    nbthread 2
    pidfile /yinzhengjie/softwares/haproxy/haproxy.pid
    log 127.0.0.1 local5 info

defaults
    option http-keep-alive
    option  forwardfor
    option redispatch
    option abortonclose
    maxconn 100000
    mode http
    timeout connect 300000ms
    timeout client  300000ms
    timeout server  300000ms
    errorloc 503 http://node107.yinzhengjie.org.cn/monitor/503.html

listen status_page
    bind 172.30.1.102:8888
    stats enable
    stats uri /haproxy-status
    stats auth    admin:yinzhengjie
    stats realm "Welcome to the haproxy load balancer status page of YinZhengjie"
    stats hide-version
    stats admin if TRUE
    stats refresh 5s

frontend WEB_PORT_80
    bind 172.30.1.102:80
    mode http
    acl php_server path_end -i .php
    use_backend nginx_php if php_server
    acl static_path path_beg -i /static /images /javascript
    #此处我们匹配了3给ACL规则,其中包括HTTP_1.1是内置的acl,TRUE也是内置的acl,而只有static_path才是咱们自定义的ACL
    use_backend apache_httpd if HTTP_1.1 TRUE static_path
    default_backend backup_web

backend nginx_php
    server web04 172.30.1.104:80  check inter 3000 fall 3 rise 5

backend apache_httpd
    server web03 172.30.1.103:80  check inter 3000 fall 3 rise 5

backend backup_web
    server web03 172.30.1.108:80  check inter 3000 fall 3 rise 5 
[[email protected] ~]# 
[[email protected] ~]# systemctl restart haproxy            #别忘记重启haproxy服务使得配置文件生效哟~
[[email protected] ~]# 
[[email protected] ~]# 

3>.查看haproxy的状态页

4>.浏览器访问"http://node102.yinzhengjie.org.cn/images/01.jpeg"

5>.浏览器访问"http://node102.yinzhengjie.org.cn/index.php"

6>.浏览器访问"http://node102.yinzhengjie.org.cn/index.html"

 

Guess you like

Origin www.cnblogs.com/yinzhengjie/p/12153787.html