layout: post
title: HAproxy简介和配置
date: 2018-03-13
tags: [“Haproxy”,”软件服务”]
一、HAproxy简介
HAProxy是一个免费的负载均衡软件,可以运行于大部分主流的Linux操作系统上。HAproxy可以实现4层和7层的两种负载能力,其稳定性和负载能力得到了广大的好评。
HAProxy的核心功能:
: - 通过静态的cookies来路由http请求
: - 在确保服务器持久性的同时在多个服务器之间传播负载
: -可以使用http的cookies
: - 主server宕机可以使用backupserver作为填充
: - 接受连接到专用于服务监控的特殊端口
: - 停止接受连接而不破坏现有连接
: - 可以直接添加、删除、修改请求和响应报文的报文头部
: - 通过正则表达式阻塞请求
: - 可以通过页面查看均衡器的状态和修改后端节点
二、HAproxy的global配置说明
1、配置段:
global:全局配置段
进程及安全配置相关的参数
性能调整相关参数
Debug参数
用户列表
peers
proxies:代理配置段
defaults:为frontend, listen, backend提供默认配置;
fronted:前端,相当于nginx, server {}
backend:后端,相当于nginx, upstream {}
listen:同时拥前端和后端,It is generally useful for TCP-only traffic.
2、global配置参数
global
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
nbproc <number>:要启动的haproxy的进程数量;官方建议保持单进程,当开启多进程时,部分问题的无法做错误追踪,而单进程模式也可以处理几万的并发。
ulimit-n <number>:每个haproxy进程可打开的最大文件数;haproxy可以自行调整,所以这里无需设置
log <address> [len <length>] <facility> [max level [min level]]
性能优化
maxconn <number>:设定每个haproxy进程所能接受的最大并发连接数;Sets the maximum per-process number of concurrent connections to <number>. 总体的并发连接数:nbproc * maxconn
maxconnrate <number>:每个进程每秒种所能创建的最大连接数量;
maxsessrate <number>:将每秒会话数的最大值设置为<number>。当达到此限制时,代理将停止接受连接。 无论每个前端容量如何,它都可以用来限制全局容量。 值得注意的是,这只能用作服务保护措施,因为在达到限制时,前端之间不一定会有公平的份额,所以最好将每个前端限制在接近其前端的某个值 预期的份额。 另外,降低tune.maxaccept可以提高
maxsslconn <number>:设定每个haproxy进程所能接受的ssl的最大并发连接数;
spread-checks <0..50, in percent> 在两次连续检查之间的间隔延迟上添加一些随机性,以避免以过于规律的间隔发送健康检查。 如果未设置,则默认值为0。(当后端节点过多时,用于避免并发,当后端节点过多时,该项是必须启用的)
这里详细说一下log的配置(摘自官网)
- 参数: IPv4 address'IPv6 address'A filesystem path to a UNIX domain socket
参数: 大于此值的日志行在发送之前将被截断。 原因是系统日志服务器在日志行长度上的行为不同。 所有服务器都支持1024的默认值,但有些服务器只需放置更大的线路,而其他服务器则会记录它们。 如果服务器支持较长的行,则可以在此处设置此值以避免截断长行。 同样,如果一台服务器放弃长行,最好在发送它们之前截断它们。 接受的值是80到65535(含)。 对于所有标准用法,默认值1024通常都很好。 长捕获或JSON格式日志的一些特定情况可能需要较大的值。 参数:must be one of the 24 standard syslog facilities for example: kern user mail daemon auth syslog lpr news uucp cron auth2 ftp ntp audit alert cron2 local0 local1 local2 local3 local4 local5 local6 local7
- log-format
Specifies the log format string to use for traffic logs context:defaults、frontend、listen
log-format参数见https://cbonte.github.io/haproxy-dconv/1.5/configuration.html#8.2
三、defaults配置段
配置后端的默认参数,可参考官方文档https://cbonte.github.io/haproxy-dconv/1.5/configuration.html#4.1zenggai增改
1、option forwardfor [ except
Enable insertion of the X-Forwarded-For header to requests sent to servers
except
header
if-none: 如果为空添加
2、timeout client
3、timeout server
4、timeout http-keep-alive
5、timeout http-request
6、timeout connect
7、timeout client-fin
8、timeout server-fin
9、compression
对传输的压缩配置
syntax:
- compression algo
... #启用http协议的压缩机制,指明压缩算法gzip, deflate; compression type ... #指明压缩的MIME类型;常适用于压缩的类型为文本类型; compression offload #
for example:
- compression algo gzip
- compression type text/html text/plain
“compression offload” 的使用场景:
“卸offload”设置使haproxy删除Accept-Encoding标头toprevent后端服务器压缩响应。 强烈建议不要这样做,因为这意味着所有压缩工作将在haproxy所在的单个点上完成。 但是,在一些部署方案中,haproxy可能安装在有错误的HTTP压缩实现的错误网关之前,无法关闭。在这种情况下,haproxy可用于防止该网关发出无效的有效负载。 在这种情况下,简单地删除配置中的标题不起作用,因为它在解析标题之前应用,这样可以防止haproxy压缩。 这种情况下应该使用”卸载”设置。 注意:现在,在”默认值”部分设置时,”offload”设置将被忽略。
Compression is disabled when:
该请求不会在”Accept-Encoding”头中通告支持的压缩算法 响应消息不是HTTP / 1.1
- HTTP状态码不是200
响应标题”传输编码”包含”分块”(临时解决方法) 响应既不包含”Content-Length”标题,也不包含最后一个值为”chunked”的”Transfer-Encoding”
响应包含一个”Content-Type”头,其首个值以”multipart” 响应包含”Cache-control”头中的”no-transform”值
用户代理匹配”Mozilla / 4”,除非它是XP SP2或MSIE 7及更高版本的MSIE 6 响应包含一个”Content-Encoding”头,表明响应已经被压缩(请参阅Compression offload)
四、frontend配置段
1、bind:绑定地址和端口
context:frontend or listen
syntax:
bind [address]:port_range [, …] [param]
bind /
- for example:
- frontend test
- bind :80,:443
- bind 10.0.0.1:10080,10.0.0.1:10443
- bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy
2、 default_backend
3、maxconn
定义前端并发连接数,默认为2000
context : defaults
、frontend
、listen
4、mode { tcp’http’health }
定义haproxy的工作模式;
context : defaults
、frontend
、listen
、backend
- tcp :基于layer4实现代理;可代理mysql, pgsql, ssh, ssl等协议;
- http :仅当代理的协议为http时使用;
- health :工作为健康状态检查的响应模式,当连接请求到达时回应"OK"后即断开连接;
5、reqadd
context:listen
、backend
、frontend
Add a header at the end of the HTTP request
6、reqdel
reqidel
context:listen
、backend
、frontend
Delete all headers matching a regular expression in an HTTP response
7、rspadd
context:listen
、backend
、frontend
Add a header at the end of the HTTP response
for example:
- rspadd X-Via:\ HAPorxy
8、rspdel
rspidel
Delete all headers matching a regular expression in an HTTP request
for example:
- rspidel Server.*
9、use_backend
Switch to a specific backend if/unless an ACL-based condition is matched.当符合指定的条件时使用特定的backend;
五、backend配置段
1、balance
context:defaults、backend、listen
syntax:
balance
balance url_param [check_post]
Arguments :
算法
- roundrobin:Each server is used in turns, according to their weights. server options: weight #动态算法:支持权重的运行时调整,支持慢启动;每个后端中最多支持4095个server;
- static-rr: 静态算法:不支持权重的运行时调整及慢启动;后端主机数量无上限;
- leastconn: 推荐使用在具有较长会话的场景中,例如MySQL、LDAP等;
- first: 根据服务器在列表中的位置,自上而下进行调度;前面服务器的连接数达到上限,新请求才会分配给下一台服务;
- source:
- 源地址hash;(不建议使用,因为client访问internet一般都是通过NAT的方式访问的,也就是说,会有大量的用户使用同一个IP地址,这种方式会造成调度的不均匀分配,可以使用cookie的方式来代替。)
- 除权取余法:
- 一致性哈希:
- uri: 对URI的左半部分做hash计算,并由服务器总权重相除以后派发至某挑出的服务器;this can be changed using "hash-type"
:// : @ : / ; ? # 左半部分:/ ; 整个uri:/ ; ? # url_param:对用户请求的uri听 部分中的参数的值作hash计算,并由服务器总权重相除以后派发至某挑出的服务器;通常用于追踪用户,以确保来自同一个用户的请求始终发往同一个Backend Server;this can be changed using "hash-type" hdr( ):对于每个http请求,此处由 指定的http首部将会被取出做hash计算; 并由服务器总权重相除以后派发至某挑出的服务器;没有有效值的会被轮询调度; this can be changed using "hash-type" hdr(Cookie) hash-type:哈希算法 hash-type map-based:除权取余法,哈希数据结构是静态的数组; consistent:一致性哈希,哈希数据结构是一个树; is the hash function to be used : 哈希函数 sdbm、djb2、 wt6
2、server 定义后端主机的各服务器及其选项;
syntax:
- server
[:port] [settings ...] default-server [settings ...]
[:[port]]:端口映射;省略时,表示同bind中绑定的端口;
[settings]:参数(常用参数如下)
- maxconn
:当前server的最大并发连接数; backlog :当前server的连接数达到上限后的后援队列长度; backup:设定当前server为备用服务器; check:对当前server做健康状态检测; addr :检测时使用的IP地址; port :针对此端口进行检测; inter :连续两次检测之间的时间间隔,默认为2000ms; rise :连续多少次检测结果为"成功"才标记服务器为可用;默认为2; fall :连续多少次检测结果为"失败"才标记服务器为不可用;默认为3; cookie :为当前server指定其cookie值,用于实现基于cookie的会话黏性; disabled:标记为不可用; on-error :后端服务故障时的行动策略; - fastinter: force fastinter - fail-check: simulate a failed check, also forces fastinter (default) - sudden-death: simulate a pre-fatal failed health check, one more failed check will mark a server down, forces fastinter - mark-down: mark the server immediately down and force fastinter redir :将发往此server的所有GET和HEAD类的请求重定向至指定的URL; weight :权重,默认为1;
注意:httpchk,”smtpchk”, “mysql-check”, “pgsql-check” and “ssl-hello-chk” 用于定义应用层检测方法;
3、cookie
对于cookie的定义
syntax:cookie
context:defaults、listen、backend
参数含义如下:
:is the name of the cookie which will be monitored, modified or inserted in order to bring persistence. rewirte:该关键字表示cookie将由服务器提供,haproxy将修改其值以在其中设置服务器的标识符。 当对"Set-cookie"和"Cache-control"头的复杂组合进行管理留给应用程序时,该模式非常方便。 应用程序可以决定是否适合发出持久性cookie。 由于应该监视所有响应,因此该模式在HTTP隧道模式下不起作用。 除非应用程序行为非常复杂和/或中断,否则建议不要以新模式启动新部署。改param与"insert","prefix"相冲突。 insert:此关键字指示如果客户端尚未拥有允许其访问此服务器的cookie,则持久cookie将必须由haproxy插入到服务器响应中。 在没有"保存"选项的情况下使用时,如果服务器发出具有相同名称的cookie,则它在处理之前将被删除。 出于这个原因,可以使用此模式升级以"重写"模式运行的现有配置。 该cookie只会是一个会话cookie,不会存储在客户端的磁盘上。 默认情况下,除非添加"间接"选项,否则服务器将看到客户端发出的Cookie。 由于缓存效果,添加"nocache"或"postonly"关键字通常是明智的(见下文)。 与"rewirte"和"prefix"关键字不兼容。 prefix:该关键字表示不是依赖专用cookie来保存持久性,而是完成一个现有的cookie。 这可能在客户端不支持多个单个cookie并且应用程序已经需要它的某些特定环境中需要。 在这种情况下,只要服务器设置一个名为 的cookie,它将以服务器的标识符和分隔符为前缀。 前缀将从所有客户端请求中删除,以便服务器仍然可以找到它发出的cookie。 由于所有请求和响应都可能被修改,因此该模式不适用于隧道模式。 与"insert"和"rewirte"关键字不兼容。 注意:强烈建议不要将"indirect"与"prefix"一起使用,否则服务器cookie更新不会发送给客户端。 indirect:如果指定了此选项,则不会将Cookie发送给已有有效cookie的客户端(服务器端处理过的)。 如果服务器本身设置了这样的cookie,它将被删除,除非设置了"preserve"选项。 在"insert"模式下,这将另外从发送到服务器的请求中删除cookie,从应用程序的角度使持久性机制完全透明。 注意:强烈建议不要将"indirect"与"prefix"一起使用,否则服务器cookie更新不会发送给客户端。 nocache:当客户端与HAProxy之间存在缓存时,建议将此选项与insert模式结合使用,因为它确保如果需要插入cookie,则可缓存响应将被标记为不可缓存。 这一点很重要,因为如果所有持久性Cookie都添加到可缓存的主页上,则所有客户都将从外部缓存中获取页面,并且将共享相同的持久性cookie,从而导致一台服务器接收的流量远远超过其他客户端。 另见"insert"和"postonly"选项。 postonly: 此选项可确保仅在对POST请求的响应中执行cookie插入。 它是"nocache"选项的替代方案,因为POST响应不可缓存,所以这可确保持久性Cookie永远不会被缓存。 由于大多数站点在第一次POST之前不需要任何类型的持久性,通常是登录请求,所以这是一种非常高效的优化缓存的方法,无需在缓存中找到持久性cookie。 preserve:该选项只能用于"insert"或"indirect"。 它允许服务器本身发出持久性cookie。 在这种情况下,如果在响应中找到cookie,haproxy将保持不变。 这对于在实例的注销请求之后结束持久性很有用。 为此,服务器只需发出一个无效值的cookie(例如:空)或过去的日期。 通过将此机制与"禁用404"检查选项相结合,可以执行完全正常关闭,因为用户在注销后肯定会离开服务器。 httponly:该选项告诉haproxy在插入cookie时添加"HttpOnly"cookie属性。 此属性用于使用户代理不会与非HTTP组件共享该Cookie。 secure:该选项告诉haproxy在插入cookie时添加"安全"Cookie属性。 该属性用于使用户代理永远不会通过非安全通道发送此cookie,这意味着通过此标志学习的cookie将仅通过SSL / TLS连接呈现。 domain:该选项允许指定插入cookie的域。 它只需要一个参数:一个有效的域名。 如果域名以点开头,则允许浏览器将其用于任何以该名称结尾的主机。 也可以通过多次调用此选项来指定多个域名。 有些浏览器可能对域的数量有小的限制,所以在做这些时要小心。 maxidle:该选项允许插入的cookie在空闲时间后被忽略。它只适用于插入模式的Cookie。当一个cookie被发送到客户端时,这个cookie被发送的日期也被发送。在进一步演示此cookie时,如果日期比参数指示的延迟更早(以秒为单位),则会被忽略。否则,如果需要将响应发送到客户端,它将被刷新。这对于防止永不关闭浏览器的用户在同一台服务器上保留时间过长(例如:在更改服务器场大小后)特别有用。当这个选项被设置并且cookie没有日期时,它总是被接受,但在响应中被刷新。这保持了管理员访问他们的网站的能力。未来的日期超过24小时的Cookie将被忽略。这样做可以让管理员修复时区问题,而不会冒用户离开网站的风险。 maxlife:此选项允许插入的Cookie在一段时间后被忽略,无论它们是否正在使用。它只适用于插入模式cookie。当cookie首次发送给客户端时,发送此cookie的日期也会发送。在进一步演示此cookie时,如果日期比参数指示的延迟更早(以秒为单位),则它将被忽略。如果请求中的Cookie没有日期,则会被接受并设置日期。未来的日期超过24小时的Cookie将被忽略。这样做可以让管理员修复时区问题,而不会冒用户离开网站的风险。与maxidle相反,这个值不会刷新,只有第一次访问的日期才算。当时可能会使用maxidle和maxlife。这对于防止永不关闭浏览器的用户在同一台服务器上保留时间过长(例如:在更改服务器场大小后)特别有用。这比maxidle方法更强,因为它会在一定的绝对延迟后强制执行重新调度。
示例:
- 实现session sticky
- backend websrvs
- cookie WEBSRV insert nocache indirect
- server srv1 172.16.100.6:80 weight 2 check rise 1 fall 2 maxconn 3000 cookie srv1
- server srv2 172.16.100.7:80 weight 1 check rise 1 fall 2 maxconn 3000 cookie srv2
4、errorfile
Return a file contents instead of errors generated by HAProxy
context:all
- code:HTTP status code
- file:Be recommended error file
for example:
- errorfile 400 /etc/haproxy/errorfiles/400badreq.http
- errorfile 408 /dev/null # workaround Chrome pre-connect bug
- errorfile 403 /etc/haproxy/errorfiles/403forbid.http
- errorfile 503 /etc/haproxy/errorfiles/503sorry.http
5、errorloc
errorloc302
- Return an HTTP redirection to a URL instead of errors generated by HAProxy
- code:HTTP status code
- url:Be recommended error uri
6、option httpchk
syntax:
- option httpchk
option httpchk option httpchk
定义基于http协议的7层健康状态检测机制;
syntax:http-check expect [!]
- Make HTTP health checks consider response contents or specific status codes
六、listen配置段
包括frontend和backend的配置,listen端主要用作tcp的转发,这里不详说
七、状态页stats
大多数stats配置可以用于defaults
、listen
、backend
、frontend
上下文
1、stats enable
基于默认的参数启用stats page有如下配置
- - stats uri : /haproxy?stats
- - stats realm : "HAProxy Statistics"
- - stats auth : no authentication
- - stats scope : no restriction 状态统计:没有限制
2、stats auth :认证时的账号和密码,可使用多次;
3、stats realm 认证时的realm;
4、stats uri 自定义stats page uri stats refresh 设定自动刷新时间间隔;
5、stats admin { if ‘ unless } 启用stats page中的管理功能(默认不启用,不安全,不可用于defaults
上下文)、
6、stats refresh 页面数据刷新间隔
7、stats scope { ‘ “.” } 启用统计信息并限制访问范围
总体配置示例1:
- listen stats
- bind :9099
- stats enable
- stats realm HAPorxy\ Stats\ Page
- stats auth admin:admin
- stats admin if TRUE
总体配置示例2:
- listen stats
- bind :9099
- stats enable
- stats hide-version
- stats scope .
- stats uri /admin?stats
- stats realm Haproxy\ Statistics
- stats auth admin1:AdMiN123
- stats auth admin2:AdMiN321
八、ACL访问控制
1、acl
acl [flags] [operator] …
Declare or complete an access list.
context : defaults
、frontend
、listen
for example:
- acl invalid_src src 0.0.0.0/7 224.0.0.0/3
- acl invalid_src src_port 0:1023
- acl local_dst hdr(host) -i localhost
的类型:
- - boolean
- - integer or integer range
- - IP address / network
- - string (exact, substring, suffix, prefix, subdir, domain)
- - regular expression
- - hex block
- -i : ignore case during matching of all subsequent patterns.
- -m : use a specific pattern matching method
- -n : forbid the DNS resolutions
- -u : force the unique id of the ACL
- -- : force end of flags. Useful when a string looks like one of the flags.
[operator]
匹配整数值:
- eq、ge、gt、le、lt
匹配字符串:
- - exact match (-m str) : the extracted string must exactly match the patterns ;
- - substring match (-m sub) : the patterns are looked up inside the extracted string, and the ACL matches if any of them is found inside ;
- - prefix match (-m beg) : the patterns are compared with the beginning of the extracted string, and the ACL matches if any of them matches.
- - suffix match (-m end) : the patterns are compared with the end of the extracted string, and the ACL matches if any of them matches.
- - subdir match (-m dir) : the patterns are looked up inside the extracted string, delimited with slashes ("/"), and the ACL matches if any of them matches.
- - domain match (-m dom) : the patterns are looked up inside the extracted string, delimited with dots ("."), and the ACL matches if any of them matches.
acl作为条件时的逻辑关系:
- - AND (implicit)
- - OR (explicit with the "or" keyword or the "''" operator)
- - Negation with the exclamation mark ("!")
for example:
- if invalid_src invalid_port
- if invalid_src '' invalid_port
- if ! invalid_src invalid_port
:
- dst : ip
- dst_port : integer
- src : ip
- src_port : integer
for example:
- acl invalid_src src 172.16.200.2
path : string
This extracts the request’s URL path, which starts at the first slash and ends before the question mark (without the host part).
for example:
- /path;
syntax:
- path : exact string match
- path_beg : prefix match
- path_dir : subdir match
- path_dom : domain match
- path_end : suffix match
- path_len : length match
- path_reg : regex match
- path_sub : substring match
for example:
- path_beg /images/
- path_end .jpg .jpeg .png .gif
- path_reg ^/images.*\.jpeg$
- path_sub image
- path_dir jpegs
- path_dom ilinux
- /images/jpegs/20180312/logo.jpg
url : string
This extracts the request’s URL as presented in the request. A typical use is with prefetch-capable caches, and with portals which need to aggregate multiple information from databases and keep them in caches.
syntax:
- url : exact string match
- url_beg : prefix match
- url_dir : subdir match
- url_dom : domain match
- url_end : suffix match
- url_len : length match
- url_reg : regex match
- url_sub : substring match
req.hdr([[,]]) : string
This extracts the last occurrence of header in an HTTP request.
- hdr([
[,]]) : exact string match hdr_beg([[,]]) : prefix match hdr_dir([[,]]) : subdir match hdr_dom([[,]]) : domain match hdr_end([[,]]) : suffix match hdr_len([[,]]) : length match hdr_reg([[,]]) : regex match hdr_sub([[,]]) : substring match
for example:
- acl bad_curl hdr_sub(User-Agent) -i curl
- block if bad_curl
status : integer
返回HTTP响应中包含HTTP状态码的整数,例如302.它主要用于ACL和整数范围内,例如,如果响应不是3xx,则删除任何位置标头。
2、内建ACL
- ACL name Equivalent to Usage
- FALSE always_false never match
- HTTP req_proto_http match if protocol is valid HTTP
- HTTP_1.0 req_ver 1.0 match HTTP version 1.0
- HTTP_1.1 req_ver 1.1 match HTTP version 1.1
- HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length
- HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme
- HTTP_URL_SLASH url_beg / match URL beginning with "/"
- HTTP_URL_STAR url * match URL equal to "*"
- LOCALHOST src 127.0.0.1/8 match connection from local host
- METH_CONNECT method CONNECT match HTTP CONNECT method
- METH_GET method GET HEAD match HTTP GET or HEAD method
- METH_HEAD method HEAD match HTTP HEAD method
- METH_OPTIONS method OPTIONS match HTTP OPTIONS method
- METH_POST method POST match HTTP POST method
- METH_TRACE method TRACE match HTTP TRACE method
- RDP_COOKIE req_rdp_cookie_cnt gt 0 match presence of an RDP cookie
- REQ_CONTENT req_len gt 0 match data in the request buffer
- TRUE always_true always match
- WAIT_END wait_end wait for end of content analysis
3、ACL调用之block(阻塞acl列表访问)
syntax:
block { if ‘ unless }
for example:
- acl invalid_src src 0.0.0.0/7 224.0.0.0/3
- acl invalid_src src_port 0:1023
- acl local_dst hdr(host) -i localhost
- block if invalid_src '' local_dst
4、use_backend
Switch to a specific backend if/unless an ACL-based condition is matched.
context:frontend、listen
for example:
- frontend
- bind 80
- use_backend staticsrvs if url_static
- default_backend webserver
5、 http-request { allow ‘ deny } [ { if ‘ unless } ]
Access control for Layer 7 requests
context:frontend、backend、listen
6、tcp-request connection {accept’reject} [{if ‘ unless} ]
Perform an action on an incoming connection depending on a layer 4 condition
context:frontend、backend、listen
for example:
- listen ssh
- bind :22022
- balance leastconn
- acl invalid_src src 172.16.200.2
- tcp-request connection reject if invalid_src
- mode tcp
- server sshsrv1 172.16.100.6:22 check
- server sshsrv2 172.16.100.7:22 check backup
九、SSL配置
1、http —> https
必须在mod http的模式下进行
1) 支持ssl会话;
- bind *:443 ssl crt /PATH/TO/SOME_PEM_FILE
crt后的证书文件要求PEM格式,且同时包含证书和与之匹配的所有私钥;
- cat demo.crt demo.key > demo.pem
2) 把80端口的请求重向定443;
- bind *:80
- redirect scheme https if !{ ssl_fc }
另一种配置:对非ssl的任何url的访问统统定向至https主机的主页;
- redirect location https://172.16.0.67/ if !{ ssl_fc }
3) 如何向后端传递用户请求的协议和端口
- http_request set-header X-Forwarded-Port %[dst_port]
http_request add-header X-Forwared-Proto https if { ssl_fc }