Nginx 从旧子域重定向到新子域

时间:2021-01-09 09:15:58

标签: nginx http-redirect

我想将所有流量从旧子域重定向到新子域,但出了点问题 =)

这是我的配置:

# Redirect from http to https
server {
  listen 80 default deferred; # for Linux
  return 301 https://$host$request_uri;
}

# Redirect section - from old to new sub
server {
  listen 80;
  listen 443 ssl http2;

  server_name old.domain.com www.old.domain.com;
  return 301 https://new.domain.com$request_uri;

  # should I use SSL while redirecting? without old certs nginx gives me an error...
  ssl_certificate ...
  ...
}

# main working subdomain
server {
  listen 443 ssl http2;
  server_name new.domain.com www.new.domain.com;
  root ...
  ...
}

使用此配置,我可以访问 new.domain.com 并且它可以使用有效的 SSL 证书按预期工作,但旧的 old.domain.com 也无需重定向即可访问:(

1 个答案:

答案 0 :(得分:0)

我的变体正在运行,这是 DNS 提供商方面的错误(DNS 记录、CNAME 有问题)