Score:0

Nginx subdomain is rerouting to main domain

pr flag
Tom

I have an nginx webserver hosting an old site. This site has been migrated to a new site but I want to keep the old site live on a subdomain, legacy2.example.com. I've gone through and modified the sites-enabled and sites-available config files and linked them, as well as created an A record to legacy2.example.com pointing to this IP, however it is still redirecting to domain.com, not legacy2.example.com. I'm including my config file below. Is there some other config in nginx that could be telling it to redirect?

I've followed along with similar questions and basic guides, but even with changing the server_name field I can't seem to get

 server {
    listen     80;
    listen     [::]:80;
    server_name legacy2.example.com wwww.legacy2.example.com;

    
    location /.well-known {
       root /var/www/prod.example.com/current;
       try_files $uri =404;
    }

    location / {
      if ($http_user_agent ~* SemrushBot|ByteSpider|YandexBot|AhrefsBot|DotBot) {
        return 403;
      }
      return 301 https://$http_host$request_uri;
    }
 }

server {
    listen     8080;
    listen     [::]:8080;
    server_name legacy2.example.com wwww.legacy2.example.com;
   
    set $MAGE_ROOT /var/www/prod.example.com/current;
    set $MAGE_MODE production;

    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;

    include /var/www/prod.example.com/current/nginx.conf.sample;

    error_log  /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;
}

server {
    listen   443 ssl;
    listen   [::]:443 ssl;
    server_name legacy2.example.com wwww.legacy2.example.com;

    ssl_certificate "/etc/nginx/ssl/example.com.pem";
    ssl_certificate_key "/etc/nginx/ssl/example.com.key";

    client_max_body_size 128M;

    error_log  /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    # Enable to bypass Varnish
    # set $MAGE_ROOT /var/www/prod.example.com/current;
    # set $MAGE_MODE production;
    # include /var/www/prod.example.com/current/nginx.conf.sample;

    # Varnish
    location / {
        if ($http_user_agent ~* SemrushBot|ByteSpider|YandexBot|AhrefsBot|DotBot) {
            return 403;
        }

        proxy_pass http://127.0.0.1:6081;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Ssl-Offloaded "1";
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        # proxy_set_header X-Forwarded-Proto $scheme;

       #proxy_headers_hash_max_size 512;
       #proxy_headers_hash_bucket_size 128; 
    }
}
us flag
Have you changed the base URL of the application that is now running at `www.legacy2.example.com`? There is nothing in your nginx configuration that would do such a redirect.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.