在网上找了下,国内没有多少介绍haproxy的,好像都是nginx多一些,但是在大多数容器化部署的今天,人们好像总是要使用docker去部署一下子,折腾半天,记录一下(此篇主要讲用docker部署haproxy,主要功能有端口转发,负载均衡,根据api路径转发这三种)
1. 执行 `docker pull haproxy:1.7`
2. 我准备了一份docker-compose 文件,方便启动调试:
version: '3'
services:
haproxy:
image: haproxy:1.7
container_name: haproxy_v1
restart: always
volumes:
- /home/test-haproxy/haproxy:/etc/haproxy:ro
command: ["haproxy", "-f", "/etc/haproxy/haproxy.cfg"]
ports:
- 80:80
- 443:443
- 3000:3000
- 5000:5000
3. haproxy配置文件,放入 `/home/test-proxy/haproxy` 中,文件名字为haproxy.cfg
global
ulimit-n 51200
defaults
log global
mode http
option dontlognull
timeout connect 1000ms
timeout client 150000ms
timeout server 150000ms
# 1.普通端口转发
fro