【问题标题】:HAproxy redirect all root requests to wwwHAproxy 将所有根请求重定向到 www
【发布时间】:2017-03-24 09:43:45
【问题描述】:

我刚刚在服务器上安装了 HAproxy,它不应该作为任何传入裸域请求(http 和 https)的重定向端点到 www.-version。就像服务 wwwizer.com。这是我的配置文件:

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 ciphers(1SSL). This list is from:
        #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
        ssl-default-bind-options no-sslv3

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http

frontend http
        bind *:80
        bind *:443

        acl has_www hdr_beg(host) -i www
        http-request redirect code 301 location www.%[hdr(host)]%[req.uri] unless has_www 

我的域 DNS 的 A 记录指向服务器的 IP。但是,如果我转到 http://exmaple_url.com 我会被转发到:http://exmaple_url.com/www.exmaple_url.com 而不仅仅是 http://www.exmaple_url.com

我做错了什么?

我按照文档中的说明进行操作:https://www.haproxy.com/doc/aloha/7.0/haproxy/http_redirection.html

【问题讨论】:

    标签: redirect haproxy


    【解决方案1】:

    我希望将 https:// 添加到重定向位置是您需要的修复:

    http-request redirect code 301 location https://www.%[hdr(host)]%[req.uri] unless has_www

    【讨论】:

      【解决方案2】:

      为使用此答案的任何人更新。规范一定已经改变了,我需要使用这个修改后的 http-request 来工作:

      http-request redirect code 301 location https://www.%[hdr(host)]%[capture.req.uri] unless has_www
      

      根据第 7.3.6 节。有关 req.uri 的文档:
      https://www.haproxy.org/download/2.4/doc/configuration.txt

      这是我对 HA-Proxy 版本 2.3.9-53945bf 2021/03/30 的体验

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-27
        • 2012-05-11
        • 1970-01-01
        • 1970-01-01
        • 2018-05-02
        • 2013-04-03
        • 2015-09-30
        • 2022-01-09
        相关资源
        最近更新 更多