LoginSignup
1
1

More than 5 years have passed since last update.

HAProxyでACLを使ってURLごとにサーバを振り分ける

Last updated at Posted at 2018-10-03

サブディレクトリでWebサーバの振り分けを検証してみます。
HAProxyはCentOS7で構築します。

HAProxyをインストール

HAProxyをyumでインストールする。

# yum install haproxy

サーバを振り分ける条件を追加

HAProxy設定でサーバを振り分ける条件を追加する

/etc/haproxy/haproxy.cfg
frontend main
  option forwardfor
  bind 0.0.0.0:80
  acl is_hoge path_beg /hoge
  acl is_fuge path_beg /fuge
  use_backend hoge_backend if is_hoge
  use_backend fuge_backend if is_fuge

backend hoge_backend
  option forwardfor
  reqirep ([^\ ]*)\ /hoge/(.*) \1\ /hoge/\2
  server hoge 192.168.0.101:80 check

backend fuge_backend
  option forwardfor
  reqirep ([^\ ]*)\ /fuge/(.*) \1\ /fuge/\2
  server fuge 192.168.0.102:80 check

HAProxyを起動する。

# systemctl start haproxy

これだけで簡単に振り分けが出来ました!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1