Skip to Content
Menu
This question has been flagged
1 Reply
7164 Views

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
}


Avatar
Discard
Best Answer

There is a conflict with the server names in your NGINX configuration. 

Remove the duplicated server block for old-name.example.com

server {    server_name old-name.example.com;
    return 301 new-name.example.com$request_uri;
}

Update the existing server block for old-name.example.com to handle both HTTP and HTTPS redirects.

server {

    listen 80;
    listen 443 ssl;
 
    server_name old-name.example.com;
 
    if ($scheme = http) {
        return 301 https://new-name.example.com$request_uri;
    }
   
    return 404;
}

Update the existing server block for new-name.example.com to handle HTTP and HTTPS requests.

server {

    listen 80;
    listen 443 ssl;
 
    server_name new-name.example.com;
 
    location / {
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,x-auth';
        [some config...]
    }
 
    [ssl config...]
}

Remember to replace old-name.example.com and new-name.example.com with your actual domain names. After making these changes, Restart NGINX,  Now You can verify your URL with this tool, Redirect Checker to get a detailed redirection path and its status code.

I hope it helps you


Avatar
Discard
Related Posts Replies Views Activity
1
Jul 18
8472
3
May 24
18146
3
May 24
15236
0
Sep 23
1679
1
Dec 23
34680