does anyone know how the interaction works in Nginx?
I currently have a subdomain, let’s call it subdomain1, I want to change it to subdomain2.
To be more specific.
I run everything in a docker container and my certificate will be for subdomain2. And there will be no more servers with subdomain1.
I want to keep the traffic from google for subdomain1, but the name is not appropriate anymore and it needs to be changed to subdomain2.
Does something like this work? Will there be any issues?
server {
server_name subdomain1.mydomain.com;
return 301 http://www.subdomain2.mydomain.com/$request_uri;
}
3
Answers
Something like that could match :
8066 is for my test purpose to redirect to google.com.
If y try
localhost:8066/foo
, I go tohttps://www.google.com/foo
Note that
redirect
keyword makes it temporary. For a permanent redirection, usepermanent
instead.Yes, your approach will work. Following points might be helpful:
server { server_name subdomain1.mydomain.com; return 301 $scheme://subdomain2.mydomain.com$request_uri; }
Section
server
in nginx has two required parameterslisten
andserver_name
. Addlisten
to your config and it will workMan about server https://nginx.org/en/docs/http/ngx_http_core_module.html#server
Example