【发布时间】:2015-03-04 02:33:53
【问题描述】:
我们有一个应用程序,我们为每个客户的安装使用子域。所以我们有 customer1.ourapp.com、customer2.ourapp.com、customer3.ourapp.com 等等。
出于安全考虑,我们希望将所有 http 重定向到 https,因为我们有一个通配符 SSL 证书。 此外,有些客户不是那么精通技术并将 www 添加到他们的域名中,因此您会得到类似:http://www.customer1.ourapp.com 或 https://www.customer1.ourapp.com。在这些情况下,由于子子域,SSL 证书无效。
我正在尝试为 nginx 编写 vhost 配置,以便在这两种情况下进行正确的重定向。我得到了 http 到 https 的重定向来使用:
server {
listen 80;
server_name *.ourapp.com;
#Rewrite all nonssl requests to ssl.
return 301 https://$host$request_uri$is_args$args;
}
正确使用网址:
server {
listen 443;
server_name *.ourapp.com;
#Rest of config
}
尝试了子子域,但不匹配:
server {
server_name "~^(.*)\.(.*)\.ourapp\.com$";
return 301 https://$2.ourapp.com$request_uri;
}
知道如何让它工作吗?
【问题讨论】: