我正在尝试根据下面 POST 正文中标识的 URL 将以下请求路由到适当的服务器。我希望通过使用 HAProxy 的反向代理来实现这一点。
例如,我想将所有请求定向到 HAProxy,而不是让 HAProxy 检查 POST 正文中是否存在某些值(例如通知 url 值“pingpong”),如果是这种情况,请将流量路由到我将指定的内点在配置中。
POST /someURL/file.jsp HTTP/1.1
Host: 10.43.90.190:80
Content-Type: application/json
Connection: keep-alive
Accept: */*
Content-Length: 256
{"Info": {"groupName":"thisgroup1","Id":"M1234R456","id2":"TUP1234",
"countryCode":"USA","carrierCode":"USAIC","e164Address":"123456768789",
"notificationURL":"http:\/\/www.pingpong.com\/notify",
"timestamp":"2014-03-04T17:33:30.000Z"}}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以使用 acl 来搜索请求正文中的内容“乒乓”,并根据这个值,我会适当地路由它吗?
谢谢!
我有一个HAProxy配置为接受*.mysubdomain.com的请求.HAProxy将解析子域(prod或dev来自prod.mysubdomain.com或dev.mysubdomain.com)并转发到正确的后端.存在两个后端,一个用于产品,一个用于开发.每个后端包含两个服务器条目,指向每个子域上的Marathon LB实例.
子域需要JWT cookie才能在后端进行身份验证.我有公钥来检查JWT的有效性,但是希望在HAProxy中这样做.有没有办法添加我自己的代码来执行HAProxy配置中的JWT有效性检查?
HAProxy配置文件如下:
global
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
mode http
# Returns true when one of the headers contains one of the strings either isolated or delimited by dots. This is used to perform domain name matching.
acl host_dev hdr_dom(host) -i dev
acl host_prod hdr_dom(host) -i prod
acl jwtPresent req.cook(JWT) -m found
use_backend prod_domain if jwtPresent host_prod
use_backend dev_domain if jwtPresent host_dev
default_backend prod_domain …Run Code Online (Sandbox Code Playgroud) 是否可以将配置参数 (in haproxy.cfg)拆分为多行?
frontend
https-in bind :443 ssl strict-sni crt </path/to/cert1.pem> crt </path/to/cert2.pem> crt </path/to/cert3.pem> ...
Run Code Online (Sandbox Code Playgroud)
frontend
https-in bind :443 ssl strict-sni
crt </path/to/cert1.pem>
crt </path/to/cert2.pem>
crt </path/to/cert3.pem>
...
Run Code Online (Sandbox Code Playgroud)
$ /usr/sbin/haproxy -c -V -f /etc/haproxy/haproxy.cfg
[ALERT] 343/210133 (25646) : parsing [/etc/haproxy/haproxy.cfg:45] : unknown keyword 'crt' in 'frontend' section
[ALERT] 343/210133 (25646) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 343/210133 (25646) : Fatal errors found in configuration.
Run Code Online (Sandbox Code Playgroud) Kubernetes 中的 Nginx 入口控制器和 HAProxy 负载均衡器有什么区别?
我在 hsproxy.cfg 中为后端服务器使用 dns 名称,例如
backend s0
server server0 server0.x.y.local:8080
backend s1
server server1 server1.x.y.local:8080
Run Code Online (Sandbox Code Playgroud)
启动后名称解析工作正常。但是一旦后端服务器的 ipadress 更改,对 haproxy 的请求需要很长时间(例如 25 秒),然后以 503 响应(原因:SC)。它不会更新或重新解析 dns 名称。但是curl那台机器上的一个工作正常,所以操作系统正确地更新了这些 dns 条目的 ip 地址。所以看起来 haproxy 在启动时缓存 IP 地址并且从不更改它们。
我在 kubernetes 集群中使用 haproxy 作为 pod(不确定这是否重要)。
从我在官方文档中读到的内容来看,libc 选项应该使用操作系统解析吗?我试过放置init-addr libc但它没有帮助,haproxy 在机器上仍然以长时间运行的 503 响应,dns 完美解析。
我还看到在使用resolver条目时可以进行一些微调,您可以在其中配置刷新时间等。如果没有 haproxy.cfg 中的硬编码名称服务器,而只使用操作系统中的名称服务器,这是否可行?
我对 HTTP 协议和一点点 HAProxy 非常熟悉,但我以前从未真正搞过 URL 重写和重定向。现在,我有 2 个“简单”的 HTTP 重定向要求,我一直很难弄清楚。
https://appserver.example.com应重定向到https://appserver.example.com/myapp/webapp/?auth=saml将用户指向saml登录页面。https://appserver.example.com/?auth=standard应该重定向到https://appserver.example.com/myapp/webapp/?auth=standard要求 1 工作正常:
myuser:~ myuser$ curl -I https://appserver.example.com
HTTP/1.1 301 Moved Permanently
Content-length: 0
Location: https://appserver.example.com/myapp/webapp/?auth=saml
Connection: close
myuser:~ myuser$
Run Code Online (Sandbox Code Playgroud)
但我在如何实施#2 上遇到了困难。正如我所想,关键是添加一个acl,然后在匹配http-request redirect prefix时添加另一行。acl
acl is_auth_std path /?auth=standard
http-request redirect prefix /myapp/webapp/?auth=standard code 301 if is_auth_std
Run Code Online (Sandbox Code Playgroud)
但显然这还不够。/?auth=standard仍然重定向到假定的根 URL:
myuser:~ myuser$ curl -I https://appserver.example.com/?auth=standard
HTTP/1.1 301 Moved Permanently
Content-length: 0
Location: https://appserver.example.com/myapp/webapp/?auth=saml
Connection: close …Run Code Online (Sandbox Code Playgroud) nginx 开源中的上游块允许您启用与反向代理服务器的保持活动连接(文档:http : //nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive)。
Run Code Online (Sandbox Code Playgroud)Syntax: keepalive connections; Default: — Context: upstream激活缓存以连接到上游服务器。
连接参数设置保留在每个工作进程的缓存中的上游服务器的空闲保持连接的最大数量。
但是,在 nginx 开源中使用上游块有一些警告,特别是:DNS 会被缓存,直到重新启动或重新加载,而不管 TTL。这意味着,如果您使用带有 keepalive 的上游块来反向代理到 AWS 负载均衡器,当负载均衡器 IP 更改时,您将遇到停机时间,除非人员/服务重新加载或重新启动 nginx。“在变量中设置域名”(见下文),允许以 TTL 间隔或任何其他所需的间隔重新解析 DNS,但似乎不允许您启用保持连接。
是否可以在nginx开源中通过域名反向代理到另一台服务器的同时启用keepalive连接,并根据TTL重新解析DNS(无需服务器重新加载/重启)?(Nginx Plus 支持在上游块中重新解析 DNS)。如果单独使用 nginx 开源无法做到这一点,最好将 DNS 解析移动到 HAProxy 等另一层并指向 nginx 上游块中的该层?
nginx keepalive 和 dns 解析器几乎是相同的问题,但有以下区别:在这里,如果无法在 nginx 本身中完成,使用插件或不同的层是可以的。该问题的一个答案提到使用https://github.com/wdaike/ngx_upstream_jdomain,但这个插件似乎多年来没有改变,所以我怀疑将 DNS 解析移到另一层会更容易维护。
在以下对相关问题的评论中出现了类似的问题:Why does nginx proxy_pass close my connection?
在https://www.nginx.com/blog/dns-service-discovery-nginx-plus/ 中,提到了 nginx 的三种 DNS 服务发现方法,看起来它们都不允许重新解析 DNS nginx 重启/重新加载并使用上游参数,例如keepalive:
在 proxy_pass 指令中使用域名 …
我试图用docker运行haproxy.我按照这里的说明操作:
https://hub.docker.com/_/haproxy/
我能够构建docker镜像但是在尝试运行它之后.
运用
docker run -d --link another_container:another_container --name mc-ha -v haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro my_own_haproxy:latest
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
[ALERT] 298/054910 (1) : [haproxy.main()] No enabled listener found (check for 'bind' directives) ! Exiting.
Run Code Online (Sandbox Code Playgroud)
我搜索了它,但我发现的唯一的东西是ha代理的源代码.
这是我的haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see …Run Code Online (Sandbox Code Playgroud) 是否可以设置一个动态变量来保存 HTTP 标头的内容(例如 Host/X-Forwarded-Host)并稍后在 ACL 中使用?
frontend web1
# ...
set-var s1(Host)
acl site1 hdr_end(host) -i %[s1]
# ...
use_backend %[s1] if site1
Run Code Online (Sandbox Code Playgroud) 在 HAProxy 中,我使用了http-proxy 选项来使其像转发代理一样工作。这似乎工作正常,但对于 HTTPS 流量来说这是不可能的。
那么,HAProxy 配置中是否有任何选项可以像 Squid 一样代理 HTTPS 流量?
我认为问题是option https_proxy不可用。
此配置非常适合 HTTP 协议:
frontend http_proxy
bind :3128
option http_proxy
default_backend proxy_server
backend proxy_server
option http_proxy
Run Code Online (Sandbox Code Playgroud)
注意 - 我已将证书与“ssl crt”以及绑定选项一起使用,但这似乎并未通过 HTTPS 协议进行代理