我有一台服务器(debian jessie)使用 varnish 和 apache 管理多个域,我想使用 pound 将 http 流量重定向到 https。
由于 HeadRequire 指令允许使用正则表达式,因此我也尝试在 Redirect 中使用正则表达式:
ListenHTTP
Address 1.2.3.4
Port 80
## allow PUT and DELETE also (by default only GET, POST and HEAD)
xHTTP 0
RewriteLocation 0
Service "myHost"
HeadRequire "^Host: (.+)\.myserver\.net"
Redirect 301 "http://\1.myserver.net"
End
End
但不幸的是我得到了 ERR_INVALID_REDIRECT
有没有办法让 pound 进行通配符重定向?
卷曲输出:
$ curl -v http://prova.myserver.net:80/
* Hostname was NOT found in DNS cache
* Trying 1.2.3.4...
* Connected to prova.myserver.net (1.2.3.4) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: prova.myserver.net:80
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 301 Moved Permanently
< Location: http://%5c1.myserver.net/
< Content-Type: text/html
< Content-Length: 148
<
* Closing connection 0
<html><head><title>Redirect</title></head><body><h1>Redirect</h1><p>You should go to <a href="http://%5c1.myserver.net/">here</a></p></body></html>
答案1
简而言之,不可能。
基于英镑文件 Redirect 指令不允许任何模式(或正则表达式)。这也符合逻辑,因为每个服务可能有许多 HeadRequire 指令(所有指令都必须满足 Redirect 才能工作),因此如果您使用两个带有不同正则表达式的 HeadRequire 指令,Redirect 就无法猜测其中哪一个具有您想要的反向引用。
您还询问了重定向到 https,但您的示例重定向到 http。您可能省略了“s”,例如:
ListenHTTP
Address 1.2.3.4
Port 80
Service
HeadRequire "Host:.*some1.myserver.net.*"
Redirect "https://some1.myserver.net"
End
Service
HeadRequire "Host:.*some2.myserver.net.*"
Redirect "https://some2.myserver.net"
End
End
ListenHTTPS
Address 1.2.3.4
Port 443
# first domain
Cert "/etc/pki/tls/letsencrypt_pound/pound_some1.pem"
# second domain
Cert "/etc/pki/tls/letsencrypt_pound/pound_some2.pem"
Disable SSLv3
End