[英]Redirecting wildcard subdomains to a different top-level domain with nginx
我們有一堆通配符子域(_foo.example.com,bar.example.com等),當通過HTTPS訪問時,應該重定向到我們的安全域上的等效子域。
一些例子:
我認為這可以通過nginx重寫來完成,但我不確定語法。 這是我正在嘗試的:
server {
listen 443;
server_name *.example.com;
rewrite ^(.*) https://*.secure.com$1 permanent;
}
這顯然不起作用,因為我沒有捕獲傳入的子域並在重寫中使用它。
嘗試這樣的事情(未經測試):
server {
listen 80;
listen 443 default ssl;
server_name "~^(?<name>\w\d+)\.example\.com$";
rewrite ^(.*) https://$name.secure.com$1 permanent;
}
在http://forum.slicehost.com/comments.php?DiscussionID=730上找到了這個
# redirects arbitrary subdomain (some.random.sub.example.com) to (some.random.sub.example.org)
if ($host ~* "^([^.]+(\.[^.]+)*)\.example.com$"){
set $subd $1;
rewrite ^(.*)$ http://$subd.example.org$1 permanent;
break;
}
# Simply redirects example.com to example.org
if ($host ~* "^example.com$"){
rewrite ^(.*)$ http://example.org$1 permanent;
break;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.