HAproxy 将所有根请求重定向到 www
HAproxy redirect all root requests to www
我刚刚在服务器上安装了 HAproxy,它不应该作为任何传入裸域请求(http 和 https)到 www.
版本的重定向端点。就像服务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
我希望将 https://
添加到重定向位置是您需要的修复方法:
http-request redirect code 301 location https://www.%[hdr(host)]%[req.uri] unless has_www
为使用此答案的任何人更新。规范一定已经改变,我需要使用这个修改后的 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
我刚刚在服务器上安装了 HAproxy,它不应该作为任何传入裸域请求(http 和 https)到 www.
版本的重定向端点。就像服务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
我希望将 https://
添加到重定向位置是您需要的修复方法:
http-request redirect code 301 location https://www.%[hdr(host)]%[req.uri] unless has_www
为使用此答案的任何人更新。规范一定已经改变,我需要使用这个修改后的 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