haproxy acl访问限制IP

http-request: 7层过滤

tcp-request content: tcp层过滤,四层过滤
 
注意   四层 采用 accept和reject    七层采用 allow和deny      方式和规则名称均不一样
 
详细见配置文件
 

global
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
nbproc 1
maxconn 8000
user haproxy
group haproxy
daemon

#stats socket /var/lib/haproxy/stats

defaults
mode tcp
log global
option tcplog
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 15m
timeout server 15m
#timeout http-keep-alive 10s
timeout check 10s
maxconn 6000

listen admin_stats
bind 0.0.0.0:9188
mode http
log 127.0.0.1 local3 err
#HAProxy监控页面统计自动刷新时间。
stats refresh 30s
#设置监控页面URL路径。 http://IP:9188/haproxy-status可查看
stats uri /haproxy
#统计页面密码框提示信息
stats realm welcome login\ Haproxy
#登录统计页面用户和密码
stats auth admin:123456
#隐藏HAProxy版本信息
stats hide-version
#设置TURE后可在监控页面手工启动关闭后端真实服务器
#stats admin if TRUE
#设置允许访问的IP段
acl allow_host src 10.0.0.0/8
http-request allow if allow_host
#拒绝其他IP的http请求
http-request deny

frontend api1
bind *:80
mode tcp
log global
#设置允许访问的IP段
acl allow_host src 10.0.0.0/8
tcp-request content accept if allow_host
#拒绝其他IP的http请求
tcp-request content reject
default_backend api1pool

backend api1pool
balance roundrobin
server api1 10.10.10.101:80 check inter 2000 rise 2 fall 3 maxconn 3000
server api2 10.10.10.102:80 check inter 2000 rise 2 fall 3 maxconn 3000

posted @ 2018-11-30 14:51  鸾舞春秋  阅读(3441)  评论(0编辑  收藏  举报