My website will change url, I'm trying to apply a redirect (old-name.example.com to new-name.example.com), but I'm getting the following error:
nginx: [warn] conflicting server name "old-name.example.com" on 0.0.0.0:443, ignored nginx.
Here is my nginx config file on /etc/nginx/sites-enabled/myconf.conf:
server { server_name old-name.example.com; location / { add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; # # Custom headers and headers various browsers *should* be OK with but aren't # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,x-auth'; # # Tell client that this pre-flight info is valid for 20 days # [some config....] } listen 443 ssl; # managed by Certbot [ssl config...] } server { if ($host = old-name.example.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name old-name.example.com; return 404; # managed by Certbot } server { server_name old-name.example.com; return 301 new-name.example.com$request_uri; } server { server_name new-name.example.com; location / { add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; # # Custom headers and headers various browsers *should* be OK with but aren't # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,x-auth'; # # Tell client that this pre-flight info is valid for 20 days # [some config...] } listen 443 ssl; # managed by Certbot [ssl config...] } server { if ($host = new-name.example.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name new-name.example.com; return 404; # managed by Certbot }