【发布时间】:2017-04-16 18:09:53
【问题描述】:
我想将所有请求从my.domain.de 重定向到my.domain.com,包括将http 重写为https。
重定向仅适用于http://my.domain.de,它被重定向到https://my.domain.com,这是目标。
当我调用https://my.domain.de 时,它不会被重定向。
但是当我尝试访问 my.domain.com 或 http://my.domain.com 时,重定向到 https 方案失败。奇怪,因为我在切换到 .com 域之前对 my.domain.de 使用了相同的重写规则,并且它起作用了。
这是我的 nginx.conf 文件:
# my.domain.de
server {
listen 80;
server_name my.domain.de;
return 301 https://my.domain.com$request_uri;
}
# my.domain.com
server {
listen 80;
listen 443;
ssl on;
ssl_certificate /path/to/cert;
ssl_certificate_key /path/to/key;
server_name my.domain.com;
# Url rewrite does not seem to work:
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
}
编辑: 以前我写过 .de 域中所有内容的重定向都有效。不幸的是,它只有在我输入 http://my.domain.de 或没有 http:// 时才有效 当我使用https://my.domain.de 时,由于证书无效,它会收到警告。所以my.domain.de的重写规则也有问题。
EDIT2: 现在我为 my.domain.de 重新安装了一个证书,所以我唯一知道的问题是,http://my.domain.com 没有重定向到 https。 编辑 nginx.conf:
# my.domain.de
server {
listen 80;
listen 443 ssl;
ssl_certificate /path/to/cert.de;
ssl_certificate_key /path/to/key.de;
server_name my.domain.de;
return 301 https://my.domain.com$request_uri;
}
# my.domain.com
server {
listen 80;
listen 443 ssl;
ssl_certificate /path/to/cert.com;
ssl_certificate_key /path/to/key.com;
server_name my.domain.com;
# Url rewrite does not seem to work:
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
}
【问题讨论】:
-
您有
my.domain.de的证书吗?因为没有它,您将无法真正设置来自https://my.domain.de的重定向。 -
不,因为我的 my.domain.de 证书即将到期,我想将其重定向到 my,domain.com,因为我有一个(通配符)。是不是可以在 https 握手之前做重定向?
标签: nginx https url-rewriting