首页 > 解决方案 > 将 Nginx 配置转换为 Haproxy

问题描述

我正在尝试将我的反向代理从 Nginx 迁移到 Haproxy,以使用它的健康检查、地图和监控功能。

HAProxy 配置似乎不像 Nginx 那样简单。有人可以帮我将以下 nginx 规则转换为 haproxy 配置。

  location = / {
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_pass https://myapp.azurewebsites.net;
  }
  location /test {
    proxy_pass https://myapp.azurewebsites.net;
  }
  location /test/ {
    proxy_pass https://myapp.azurewebsites.net;
  }

所以我对所有规则都有相同的后端。我在 HAProxy 配置下使用,但它仅适用于/test/但不适用于/test

acl is_domain hdr(host) -i www.domain.com
use_backend be_test if is_domain { path -i / } || { path -i -m beg /test} 

backend be_test
mode http
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
http-request replace-header Host .* myapp.azurewebsites.net
server srv01 myapp.azurewebsites.net:443 weight 1 maxconn 100  check ssl verify none

标签: reverse-proxyaclhaproxy

解决方案


日志说什么?
不确定replace-header Host是否需要,因为您的 Azure 网站应作为 VirtualHost 回复 www.domain.com。


推荐阅读