potato83
By:
potato83

Cname Wildcard Redirects to main domain only

September 4, 2016 1k views
DNS Nginx Ubuntu

I noticed recently some strange behaviour - I tried to configure CNAME wildcards for all the sites on my droplet, so that www.example.com, wwww.example.com, etc., all lead to example.com. This worked fine with the first/main site I made on my droplet, let's call that main.com. So typo.main.com goes to main.com. The funny thing is, while I tried to set up the same pattern for the other sites on my droplet, typos such as wwww.othersite.com still take me to main.com. Bit of a n00b here, probably missing something obvious...

CNAME * mainsite.com. (works)
CNAME * othersites.com (don't work)

2 comments
  • Are both sites on same droplet ? If yes you could made some mistakes in Virtual Host (Server Block) config. What web-server you use ? There is possibility that you configured Virtual Host to redirect all domains to one html root

  • Yep they're on the same droplet. I wonder if the issue has something to do with the "default server" setting? Using Nginx/Ubuntu:

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
    
            root /var/www/sammypotato.com/html;
            index index.php index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name sammypotato.com www.sammypotato.com;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to displaying a 404.
                    try_files $uri $uri/ =404;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
    
            # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
            #location /RequestDenied {
            #       proxy_pass http://127.0.0.1:8080;
            #}
            location /daryladmin {
                    auth_basic "Admin Login";
                    auth_basic_user_file /etc/nginx/pma_pass;
            }
            error_page 404 /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                    root /usr/share/nginx/html;
            }
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            #
            #       # With php5-cgi alone:
            #       fastcgi_pass 127.0.0.1:9000;
            #       # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #       deny all;
            #}
    }
    
    
    server {
            listen 80;
            listen [::]:80;
    
            root /var/www/chezteva/html;
            index index.php index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name chezteva.com www.chezteva.com;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to displaying a 404.
                    #try_files $uri $uri/ =404;
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
            #location /RequestDenied {
            #       proxy_pass http://127.0.0.1:8080;
            #}
            location /daryladmin {
                    auth_basic "Admin Login";
                    auth_basic_user_file /etc/nginx/pma_pass;
            }
            error_page 404 /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                    root /usr/share/nginx/html;
            }
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            #
            #       # With php5-cgi alone:
            #       fastcgi_pass 127.0.0.1:9000;
            #       # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #       deny all;
            #}
    }
    
    
1 Answer

Not completely sure if this is the source of the issue or just a typo in your question.

CNAME * mainsite.com. (works)
CNAME * othersites.com (don't work)

As they are written here the second record would not function since it is missing the . at the end. Without this, the DNS system will consider this to be just part of the domain name.

I assume that these CNAME records are on separate domains since having multiple wildcards on one domain would not work properly since only the first one encountered would ever be used. If you can share your actual domain name or paste your zone files in their entirety it would make it much easier to assist you in getting this working as you want it.

  • Cool, thanks for the reply. The missing dot above was indeed just a typo in my question. Here are my zone files:

    Default domain (the one all wildcards go to):

    $ORIGIN sammypotato.com.
    $TTL 1800
    sammypotato.com. IN SOA ns1.digitalocean.com. hostmaster.sammypotato.com. 1458836240 10800 3600 604800 1800
    sammypotato.com. 1800 IN NS ns1.digitalocean.com.
    sammypotato.com. 1800 IN NS ns2.digitalocean.com.
    sammypotato.com. 1800 IN NS ns3.digitalocean.com.
    sammypotato.com. 1800 IN A 104.131.61.206
    *.sammypotato.com. 1800 IN CNAME sammypotato.com.
    zb14299785.sammypotato.com. 1800 IN CNAME zmverify.zoho.com.
    sammypotato.com. 1800 IN MX 10 mx.zohomail.com.
    sammypotato.com. 1800 IN MX 20 mx2.zohomail.com.
    

    Another domain (wwww.chezteva.com goes to sammypotato.com):

    $ORIGIN chezteva.com.
    $TTL 1800
    chezteva.com. IN SOA ns1.digitalocean.com. hostmaster.chezteva.com. 1465226542 10800 3600 604800 1800
    chezteva.com. 1800 IN NS ns1.digitalocean.com.
    chezteva.com. 1800 IN NS ns2.digitalocean.com.
    chezteva.com. 1800 IN NS ns3.digitalocean.com.
    chezteva.com. 1800 IN A 104.131.61.206
    *.chezteva.com. 1800 IN CNAME chezteva.com.
    

    thanks

Have another answer? Share your knowledge.