Haproxy configuration file Description

Source: Internet
Author: User
Tags custom name haproxy

################### #全局配置信息 ########################

###### #参数是进程级的, usually associated with the operating system (OS) #########

Global

Maxconn 20480 #默认最大连接数

Log 127.0.0.1 local3 #[err warning Info Debug]

Chroot/var/haproxy #chroot运行的路径

UID #所属运行的用户uid

GID #所属运行的用户组

Daemon #以后台形式运行haproxy

Nbproc 1 #进程数量 (multiple processes can be set to improve performance)

Pidfile/var/run/haproxy.pid #haproxy的pid存放路径, the user who initiates the process must have permission to access this file

Ulimit-n 65535 #ulimit的数量限制

#################### #默认的全局设置 ######################

# #这些参数可以被利用配置到frontend, Backend,listen component # #

Defaults

Log Global

Mode http #所处理的类别 (#7层 http;4 layer TCP)

Maxconn 20480 #最大连接数

Option Httplog #日志类别http日志格式

Option Httpclose #每次请求完毕后主动关闭http通道

Option Dontlognull #不记录健康检查的日志信息

Option Forwardfor #如果后端服务器需要获得客户端真实ip需要配置的参数, you can get the client IP from the HTTP header

Option Redispatch #serverId对应的服务器挂掉后, Force-directed to other healthy servers

Option Abortonclose #当服务器负载很高的时候 to automatically end the connection that the current queue is processing longer

Stats Refresh #统计页面刷新间隔

Retries 3 #3次连接失败就认为服务不可用, can also be set by the following

Balance Roundrobin #默认的负载均衡的方式, polling method

#balance source #默认的负载均衡的方式, Nginx-like Ip_hash

#balance leastconn #默认的负载均衡的方式, minimum connection

Contimeout #连接超时

Clitimeout 50000 #客户端超时

Srvtimeout 50000 #服务器超时

Timeout Check #心跳检测超时

################### #监控页面的设置 #######################

Listen Admin_status #Frontend和Backend的组合体, name of the monitoring group, custom name on demand

Bind 0.0.0.0:65532 #监听端口

Mode HTTP #http的7层模式

Log 127.0.0.1 Local3 Err #错误日志记录

Stats Refresh 5s #每隔5秒自动刷新监控页面

Stats Uri/admin?stats #监控页面的url

Stats Realm itnihao\ Itnihao #监控页面的提示信息

Stats auth admin:admin #监控页面的用户和密码admin, multiple user names can be set

Stats Auth Admin1:admin1 #监控页面的用户和密码admin1

Stats Hide-version #隐藏统计页面上的HAproxy版本信息

Stats Admin If TRUE #手工启用/disabled, backend server (haproxy-1.4.9 later version)

ErrorFile 403/etc/haproxy/errorfiles/403.http

ErrorFile 500/etc/haproxy/errorfiles/500.http

ErrorFile 502/etc/haproxy/errorfiles/502.http

ErrorFile 503/etc/haproxy/errorfiles/503.http

ErrorFile 504/etc/haproxy/errorfiles/504.http

################ #HAProxy的日志记录内容设置 ###################

Capture request Header Host Len 40

Capture Request Header Content-length Len 10

Capture Request Header Referer Len 200

Capture response header Server Len 40

Capture response header Content-length Len 10

Capture response header Cache-control Len 8

###################### #网站监测listen配置 #####################

########## #此用法主要是监控haproxy后端服务器的监控状态 ############

Listen Site_status

Bind 0.0.0.0:1081 #监听端口

Mode HTTP #http的7层模式

Log 127.0.0.1 Local3 err #[err warning Info Debug]

Monitor-uri/site_status #网站健康检测URL, used to detect haproxy management of the website can be used, normal return 200, abnormal return 503

ACL site_dead nbsrv (server_web) LT 2 #定义网站down时的策略当挂在负载均衡上的指定backend的中有效机器数小于1台时返回true

ACL site_dead nbsrv (server_blog) LT 2

ACL site_dead nbsrv (Server_bbs) LT 2

Monitor fail if Site_dead #当满足策略的时候返回503, the online documentation says 500, the actual test is 503

Monitor-net 192.168.16.2/32 #来自192.168.16.2 log information is not logged and forwarded

Monitor-net 192.168.16.3/32

####### #frontend配置 ############

# # # # #注意, frontend configuration can define multiple ACLs for matching operations ########

Frontend http_80_in

Bind 0.0.0.0:80 #监听端口, that is, Haproxy provides a port for Web services, similar to the VIP port of LVs

Mode HTTP #http的7层模式

Log Global #应用全局的日志配置

Option Httplog #启用http的log

Option Httpclose #每次请求完毕后主动关闭http通道, Ha-proxy does not support keep-alive mode

Option Forwardfor #如果后端服务器需要获得客户端的真实IP需要配置次参数, the client IP will be available from the HTTP header

####### #acl策略配置 #############

ACL Itnihao_web Hdr_reg (host)-I ^ (www.itnihao.cn|ww1.itnihao.cn) $

#如果请求的域名满足正则表达式中的2个域名返回true-I is ignoring case

ACL Itnihao_blog Hdr_dom (host)-I blog.itnihao.cn

#如果请求的域名满足www. itnihao.cn returns True-i is ignored case

#acl Itnihao HDR (host)-I itnihao.cn

#如果请求的域名满足itnihao. CN returns TRUE-I is ignored case

#acl file_req url_sub-i killall=

#在请求url中包含killall =, this control policy returns true, otherwise false

#acl dir_req url_dir-i Allow

#在请求url中存在allow作为部分地址路径, this control policy returns true, otherwise false is returned

#acl missing_cl hdr_cnt (content-length) EQ 0

#当请求的header中Content-length equals 0 o'clock returns True

####### #acl策略匹配相应 #############

#block if MISSING_CL

#当请求中header中Content-length equals 0 block request return 403

#block If!file_req | | Dir_req

#block表示阻止请求, returns a 403 error that currently indicates that the request is blocked if the policy file_req is not met or if the policy dir_req is satisfied

Use_backend Server_web If Itnihao_web

#当满足itnihao_web的策略时使用server_web的backend

Use_backend Server_blog If Itnihao_blog

#当满足itnihao_blog的策略时使用server_blog的backend

#redirect prefix http://blog.itniaho.cn code 301 if Itnihao

When #当访问itnihao. cn, use HTTP 301 to go to http://192.168.16.3

Default_backend Server_bbs

#以上都不满足的时候使用默认server_bbs的backend

######### #backend的设置 ##############

#下面我将设置三组服务器 Server_web,server_blog,server_bbs

################# #backend server_web####################

Backend Server_web

Mode HTTP #http的7层模式

Balance Roundrobin #负载均衡的方式, roundrobin average Way

Cookie ServerID #允许插入serverid到cookie中, ServerID can be defined later

Option Httpchk get/index.html #心跳检测的文件

Server Web1 192.168.16.2:80 Cookie web1 check Inter rise 3 Fall 3 weight 1

#服务器定义, the cookie 1 indicates that ServerID is Web1,check Inter 1500 is detecting the heartbeat frequency rise 3 is 3 times correctly thought the server is available,

#fall 3 is 3 failures that the server is unavailable, weight represents the weight

Server web2 192.168.16.3:80 Cookie web2 check Inter rise 3 Fall 3 weight 2

#服务器定义, the cookie 1 indicates that ServerID is Web2,check Inter 1500 is detecting the heartbeat frequency rise 3 is 3 times correctly thought the server is available,

#fall 3 is 3 failures that the server is unavailable, weight represents the weight

################## #backend server_blog######################

Backend Server_blog

Mode HTTP #http的7层模式

Balance Roundrobin #负载均衡的方式, roundrobin average Way

Cookie ServerID #允许插入serverid到cookie中, ServerID can be defined later

Option Httpchk get/index.html #心跳检测的文件

Server Blog1 192.168.16.2:80 Cookie blog1 check Inter rise 3 Fall 3 weight 1

#服务器定义, the cookie 1 indicates that ServerID is Blog1,check Inter 1500 is detecting heartbeat frequency rise 3 is 3 times correct think server is available, Fall 3 is 3 times failure considers server unavailable, weight represents weight

Server blog2 192.168.16.3:80 Cookie blog2 check Inter rise 3 Fall 3 weight 2

#服务器定义, the cookie 1 indicates that ServerID is Blog2,check Inter 1500 is detecting heartbeat frequency rise 3 is 3 times correct think server is available, Fall 3 is 3 times failure considers server unavailable, weight represents weight

################# #backend server_bbs########################

Backend Server_bbs

Mode HTTP #http的7层模式

Balance Roundrobin #负载均衡的方式, roundrobin average Way

Cookie ServerID #允许插入serverid到cookie中, ServerID can be defined later

Option Httpchk get/index.html #心跳检测的文件

Server BBS1 192.168.16.2:80 Cookie BBS1 check Inter rise 3 Fall 3 weight 1

#服务器定义, the cookie 1 indicates that ServerID is Bbs1,check Inter 1500 is detecting heartbeat frequency rise 3 is 3 times correct think server is available, Fall 3 is 3 times failure considers server unavailable, weight represents weight

Server BBS2 192.168.16.3:80 Cookie BBS2 check Inter rise 3 Fall 3 weight 2

#服务器定义, the cookie 1 indicates that ServerID is Bbs2,check Inter 1500 is detecting heartbeat frequency rise 3 is 3 times correct think server is available, Fall 3 is 3 times failure considers server unavailable, weight represents weight


This article is from the "My Ops Time" blog, so be sure to keep this source http://aaronsa.blog.51cto.com/5157083/1741518

Haproxy configuration file Description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.