Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»HAProxy Load Balancing Setup Based On URL

    HAProxy Load Balancing Setup Based On URL

    RahulBy RahulMay 24, 20132 Mins Read

    Until today I was using the basic HAProxy settings, Today i found a task about selection of backend server basis of url request. While working on this task, I learned about HAProxy ACLs.

    Task: I have wordpress installed as http://domainname.com/blog . This domain is running from 2 back-end server and balanced by HAProxy, The task is to redirect all /blog request to only single server.

    Network Scenario for this setup

    • HAProxy Server: 192.168.1.90
    • WEB1 : 192.168.1.103
    • WEB2 : 192.168.1.105
    • Domain: tecadmin.net

    The below example includes ACL for url_beg. url_beg matches the string used in url submitted. Using the url all requests starting with /blog ( tecadmin.net/blog ) will redirect to WEB2 ( 192.168.1.105 ) Server. All other requests will redirect to one of two server ( WEB1, WEB2 ), depending on load balancing algorithm used.

    Here is a quick example of uses url_beg ACL:

    global
        log 127.0.0.1 local0 notice
        maxconn 50000
        daemon
    defaults
        log global
        mode http
        option httplog
        option dontlognull
        contimeout 120000
        clitimeout 120000
        srvtimeout 120000
        option forwardfor
        option http-server-close
    
    # Configuration for HTTP site
    frontend http-in
        bind 192.168.1.90:80
        acl is_blog url_beg  /blog
        use_backend tecadmin_blog if is_blog
        default_backend tecadmin_website
    
    backend tecadmin_blog
        mode http
        balance roundrobin  # Load Balancing algorithm
        option httpchk
        option forwardfor
        server WEB2 192.168.1.105:80 weight 1 maxconn 512 check
    
    backend tecadmin_website
        mode http
        balance roundrobin  # Load Balancing algorithm
        option httpchk
        option forwardfor
        server WEB1 192.168.1.103:80 weight 1 maxconn 512 check
        server WEB2 192.168.1.105:80 weight 1 maxconn 512 check
    

    I hope this tutorial will help you to configure some basic ACL with haproxy .Regarding full configuration settings available for the ACL are listed in the haproxy configuration doc,

    blog HAProxy haproxy.cfg url_beg
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Upgrade Git version >= 1.7.10 on CentOS 6
    Next Article SQLite3 SQL Command Uses with Examples

    Related Posts

    How to Import GPG Keys on Ubuntu & Debian (without apt-key)

    2 Mins Read

    Running a Cron job every Sunday (Weekly)

    2 Mins Read

    Scheduling a Python Script with Crontab

    2 Mins Read

    Running cron job every 12 hours (twice a day)

    Updated:August 2, 20221 Min Read

    (Resolved) Key is stored in legacy trusted.gpg Keyring

    Updated:August 9, 20222 Mins Read

    How to list all collections in MongoDB database

    1 Min Read

    2 Comments

    1. PRANAV MR on March 13, 2018 12:52 pm

      Rahul We have tried above configuration but its not working for us. please post the working config plz.

      Reply
    2. Aman on May 24, 2013 5:50 pm

      Very informative post…. I also never used ACl with haproxy, thanks

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.