【问题标题】:HAProxy how to detect url is IP address instead of domain nameHAProxy如何检测url是IP地址而不是域名
【发布时间】:2018-05-31 07:51:51
【问题描述】:

如果用户输入http://ip address,我想重定向到http://domainnamefrontend 规则是什么?

例如,此规则可以确定 www 是否以域为前缀,如果不重定向到 www.domain.com。

http-request redirect code 301 location      \
  http://www.%[hdr(host)]%[capture.req.uri]  \
  unless { hdr_beg(host) -i www }

同样,当用户在浏览器中输入 IP 地址时,我想重定向到 www.domain.com。

【问题讨论】:

    标签: redirect haproxy


    【解决方案1】:

    由于user types IP address in browser,这可能有效:

     http-request redirect code 301 location http://www.example.com%[capture.req.uri] if { hdr_reg(host) -i 127.0.0.1|192.168.1.100 }`
    

    但如果用户指定 Host: example.com 则会失败

    【讨论】:

    • 只是澄清一下:这段代码放在你的前端时,将服务器/本地主机的 IP 重定向到 FQDN。用户类型 192.168.1.100 > 被重定向到 > example.com
    【解决方案2】:

    您可以检查 Host 标头值以查看它是否与大致为 IP 地址的正则表达式匹配,例如:

    acl ACL_IS_IP hdr(host) -i -m reg (\d+)\.(\d+)\.(\d+)\.(\d+)
    http-request redirect code 301 location https://www.example.com/ if ACL_IS_IP
    

    【讨论】:

      猜你喜欢
      • 2017-01-03
      • 2014-08-13
      • 2015-09-11
      • 1970-01-01
      • 2016-11-11
      • 2018-01-05
      • 2019-12-22
      • 1970-01-01
      • 2020-08-16
      相关资源
      最近更新 更多