Redirect HAproxy将所有根请求重定向到www

Redirect HAproxy将所有根请求重定向到www,redirect,haproxy,Redirect,Haproxy,我刚刚在一台服务器上安装了HAproxy,该服务器不应充当任何传入裸域请求(http和https)的重定向端点,而应将其重定向到www.-版本。就像服务wwwizer.com一样。这是我的cfg: global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.soc

我刚刚在一台服务器上安装了HAproxy,该服务器不应充当任何传入裸域请求(http和https)的重定向端点,而应将其重定向到
www.
-版本。就像服务wwwizer.com一样。这是我的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 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 
我有一个指向服务器IP的域DNS记录。但是如果我转到
http://exmaple_url.com
我被转发到:
http://exmaple_url.com/www.exmaple_url.com
而不仅仅是
http://www.exmaple_url.com

我做错了什么


我按照文档中的说明进行操作:

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

http请求重定向代码301位置https://www.%[hdr(主机)]%[req.uri],除非有

为使用此答案的任何人更新。规范必须已更改,我需要使用此修改的http请求才能工作:

http-request redirect code 301 location https://www.%[hdr(host)]%[capture.req.uri] unless has_www
根据第7.3.6节。关于请求uri的文档的列表:

这是我使用HA Proxy版本2.3.9-53945bf 2021/03/30的经验