ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

haproxy tcp 白名单配置说明

2021-12-09 18:03:13  阅读:279  来源: 互联网

标签:haproxy errors http tcp etc 白名单 errorfile


基于acl 可以让haproxy 支持强大的访问控制以及流程处理,以下是一个简单的基于tcp-request 进行4层ip白名单的处理

参考配置

  • 环境准备
version: '3'
services:
   haproxy:
      image: haproxytech/haproxy-debian:2.5.0
      volumes:
      - "./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
      - "./iplist.lst:/etc/haproxy/iplist.lst"
      ports:
      - "9000:9000"
      - "5000:5000"
   web:
      image: nginx
  • haproxy 参考配置
 #
# THIS IS SAMPLE CONFIG, FOR TEST, NOT FOR PRODUCTION!!!
#
global
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
 
listen stats
  bind :9000
  mode http
  stats enable
  stats uri /haproxy_stats
  # Default SSL material locations
  # Default ciphers to use on SSL-enabled listening sockets.
  # For more information, see ciphers(1SSL).
 
frontend  main
    bind :5000
    tcp-request connection reject if { src -f /etc/haproxy/iplist.lst }
    default_backend             app
 
backend app
    server  app1 web:80 
 
# resolvers mydns
#     nameserver dns1 127.0.0.11:53
#     resolve_retries       3
#     timeout retry         1s
#     hold other           30s
#     hold refused         30s
#     hold nx              30s
#     hold timeout         30s
#     hold valid           10s
 
defaults
    log     global
    mode    tcp
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http
 
  • ip 清单
    此处可以配置需要禁止访问的ip列表 iplist.lst
 
# dalong
127.0.0.1
# test service ip
#172.24.0.2
# default gateway
172.24.0.1

使用

  • 启动服务
docker-compose up -d
  • 测试效果
    可以结合自己的实际修改ip清单,注意修改好了之后需要重启haproxy服务

说明

以上是一个简单的集成使用,实际上我们可以结合haproxy 提供的runtime api 以及dataplain api 还有服务发现实现一个动态的控制
以上核心是利用了 tcp-request connection reject haproxy 支持tcp以及http 的不同阶段处理

参考资料

https://www.haproxy.com/documentation/hapee/latest/onepage/#tcp-request%20connection
https://www.haproxy.com/documentation/hapee/latest/management/service-discovery/dns-service-discovery/discovery-with-a-records/
https://hub.docker.com/r/haproxytech/haproxy-debian
https://github.com/rongfengliang/haproxy-tcp-iplist
https://www.haproxy.com/documentation/hapee/latest/configuration/config-sections/resolvers/

标签:haproxy,errors,http,tcp,etc,白名单,errorfile
来源: https://www.cnblogs.com/rongfengliang/p/15668571.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有