Configure haproxy L7 Server Load balancer in Route 3-Based on URL address directory forwarding
● 3.1 prepare the RS server test environment
Create a test directory:
For name in PHP nginx PIC; do mkdir-P/var/$ name; echo $ Name>/var/$ name/index.html; done
Configure HTTP service
Delete any Apache configuration above (or restore httpd. conf)
[Root @ ha2 conf] # cd/etc/httpd/Conf
[Root @ ha2 conf] #/bin/CP httpd. conf. oldboy.110625 httpd. conf
Edit httpd. conf and add
<Directory "/Var">
Options followsymlinks
AllowOverride none
Order allow, deny
Allow from all
</Directory>
Listen 8080.
Listen 8090.
Namevirtualhost *: 80
Namevirtualhost*: 8080
Namevirtualhost*: 8090
<Virtualhost *: 80>
Serveradmin 49000448@qq.com
Servername www.etiantian.org
Serveralias etiantian.org
DocumentRoot "/var/nginx"
</Virtualhost>
<Virtualhost *: 8080>
Serveradmin 49000448@qq.com
Servername www.etiantian.org
DocumentRoot "/var/PHP"
</Virtualhost>
<Virtualhost *: 8090>
Serveradmin 49000448@qq.com
Servername www.etiantian.org
DocumentRoot "/var/PIC"
</Virtualhost>
● 3.2 configure haproxy Based on directory forwarding
Frontend oldboy_test
Bind *: 80
ACL short_domain HDR (host)-I etiantian.org
Redirect prefix http://www.etiantian.org code 301 if short_domain
# ACL lang_domain HDR (host)-I www.etiantian.org
# Use_backend staticpools if lang_domain
Default_backend staticpools
# Http://www.etiantian.org/nginx/... (HTM, HTML, CSS, JS)
Backend staticpools
Balance roundrobin
Server oldboy-1 10.0.0.151: 80 check port 80 inter 3000 fall 3
Server oldboy-2 10.0.0.151: 81 check port 81 inter 3000 fall 3
Server oldboy-3 10.0.0.151: 82 check port 82 inter 3000 fall 3
# Tip: The last two Rs are fictitious. They just tell you that adding server in this way will not affect access. The following is the same.
# Http://www.etiantian.org/php/... provide dynamic content access (ended with *. php)
Backend dynamicpools
Balance roundrobin
Cookie serverid insert indirect
Server oldboy-4 10.0.0.151: 8080 maxconn 2048 weight 50 cookie a check port 8080 inter 3000 fall 3
Server oldboy-5 10.0.0.151: 8180 maxconn 2048 weight 100 cookie B check port 8180 inter 3000 fall 3
Server oldboy-6 10.0.0.151: 8280 maxconn 2048 weight 100 cookie C check port 8280 inter 3000 fall 3
# List more detailed parameters for your reference.
# Http://www.etiantian.org/pic/... provide image content access (ended with *. jpg, *. PNG, *. GIF, etc)
Backend picpools
Balance roundrobin
Server oldboy-7 10.0.0.151: 8090 check port 8090 inter 3000 fall 3
Server oldboy-8 10.0.0.151: 8190 check port 8190 inter 3000 fall 3
Server oldboy-9 10.0.0.151: 8290 check port 8290 inter 3000 fall 3
# Tip: The names after the server are defined by yourself. Do not repeat the names.
When there are multiple servers, each pool can be configured as follows:
Cookie serverid insert indirect
Server oldboy-1 10.0.0.163: 8080 cookie ett-1-1 check port 8080 inter 3000 fall 3
Configure URL-based health check
Option httpchk head/checkstatus. jsp HTTP/1.0
● 3.3 configure the client hosts
10.0.0.162 www.etiantian.org
Tip: 10.0.0.162 is the IP address of haproxy, which is used to simulate DNS resolution. In actual configuration, it can be resolved in DNS.
● 3.4 access tests on the user end
3.4.1 check whether the hosts resolution is correct
C: \ Documents ents and Settings \ hyran> Ping www.etiantian.org
Pinging www.etiantian.org [10.0.0.162] with 32 bytes of data:
Reply from 10.0.0.162: bytes = 32 time = 5 ms TTL = 64
Reply from 10.0.0.162: bytes = 32 time <1 ms TTL = 64
Reply from 10.0.0.162: bytes = 32 time <1 ms TTL = 64
3.4.2 test the URL address to see if it meets the expected requirements
Access:
Http://www.etiantian.org/nginx/
Http://www.etiantian.org/php/
Http://www.etiantian.org/pic/
If you can return the contents of your own directory, congratulations.
The following is an example of proxy configuration.
Global
Maxconn 12345
Nbproc 2
Frontend myproxy_1000
Mode HTTP
Bind *: 10000
Monitor-Uri/haproxy
ACL baiduduty url_beg/duty
ACL baiduhost hdr_beg (host)-I www.baidu.com
ACL itrushost hdr_beg (host)-I www.itrus.com.cn
Use_backend Baidu if baiduhost
Use_backend itrus if itrushost
# Default_backend Google
Backend Baidu
Mode HTTP
Server server2 www.baidu.com: 80