Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

Nginx redirect from old subdomain to new subdomain

I want to redirect all traffic from old subdomain to new subdomain but something went wrong =)

Here is my config:

# 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 ...
  ...
}

With this config I can access to new.domain.com and it is working as expected with valid SSL cert, but old old.domain.com is also accessible without redirection :(

question from:https://stackoverflow.com/questions/65641006/nginx-redirect-from-old-subdomain-to-new-subdomain

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My variant is working, it was an error on DNS provider side (something was wrong with DNS records, CNAME)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...