Kailo
By:
Kailo

IP adress points to my subdomain

January 15, 2015 1.7k views

Hello there,

I've set up a LAMP server on an CentOS VPS, created DNS records in DigitalOcean panel as instructed by the tutorials. Everything works fine on the main domain name and sub domain.

However, if I type my IP to address bar of browser, it serves me my subdomain, not the main domain.

in my ZONE file are these records -

@ IN A 95.85.27.226
asdf IN A 95.85.27.226
www IN CNAME kailo.photography.

thank you

2 comments
  • You have two A records for the same domain? Am I interpreting your zone file incorrectly, or did you intend 'asdf' to be a subdomain using a CNAME instead?

  • Yes, I do - is it bad? "asdf" is subdomain and I though it's better to have "A" record instead of CNAME for subdomains.
    But maybe I did something different than it actually should be.. ?

2 Answers

The first vhost is used as the default vhost.

  • Ok, may I kindly ask what should I change in order to have IP adress point to my main domain? (=

    Thanks

  • Have your main domain be the first vhost.

  • Alright, so if I understand correctly it should be like this?

    @ IN A 95.85.27.226
    asdf IN CNAME @
    www IN CNAME kailo.photography.

  • No, vhosts. Not DNS records.

  • Ahh, I see, but how do I force kailo.photography be the "main" vhost, instead of subdomain?

    My Vhost files are here

    main domain

    <VirtualHost *:80>
    ServerName www.domain.com
    ServerAlias domain.com
    DocumentRoot /var/www/domain.com/publichtml
    ErrorLog /var/www/domain.com/logs/error
    log
    CustomLog /var/www/domain.com/logs/access_log combined
    </VirtualHost>

    subdomain

    <VirtualHost *:80>
    ServerName sub.domain.com
    ServerAlias sub.domain.com
    DocumentRoot /var/www/sub.domain.com/publichtml
    ErrorLog /var/www/sub.domain.com/logs/error
    log
    CustomLog /var/www/sub.domain.com/logs/access_log combined
    </VirtualHost>

  • By having your main domain be the first vhost.

  • Sir, your answers were too vague for me. But maybe you didn't want to simplify - since I gotta feeling you are like Jedi knight here and I'm your padawan.

    Anyway, I got it!

    accept my humble thanks for helping me.

    ad- this is what I did

    <VirtualHost www.domain.com:80>
    ServerName www.domain.com
    ServerAlias domain.com
    DocumentRoot /var/www/domain.com/publichtml
    ErrorLog /var/www/domain.com/logs/errorlog
    CustomLog /var/www/domain.com/logs/access_log combined
    </VirtualHost>

    subdomain
    <VirtualHost sub.domain.com:80>
    ServerName sub.domain.com
    ServerAlias sub.domain.com
    DocumentRoot /var/www/sub.domain.com/publichtml
    ErrorLog /var/www/sub.domain.com/logs/errorlog
    CustomLog /var/www/sub.domain.com/logs/access_log combined
    </VirtualHost>

Have another answer? Share your knowledge.