SoftTimur
By:
SoftTimur

Domain names are indifferent

August 20, 2015 1.4k views
Nginx DNS

Hello,

I have followed this post and tried to make two domains work on a single server.

To make thing simpler, I don't want to set up a default server.

/etc/nginx/sites-available/addbba.com

server {
        listen 80;
        listen [::]:80;

        root /var/www/addbba.com/html;
        index index.php index.html index.htm;

        server_name addbba.com www.addbba.com;

        location / {
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

/etc/nginx/sites-available/matrixandcompany.com

server {
        listen 80;
        listen [::]:80;

        root /var/www/matrixandcompany.com/html;
        index index.php index.html index.htm;

        server_name matrixandcompany.com www.matrixandcompany.com;

        location / {
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

I bought two domains addbba.com and matrixandcompany.com both from GoDaddy, I made them forward and mask to the IP 178.62.87.72 that I bought from DigitalOcean.

The result of the above configuration is that, the two URLs and 178.62.87.72 all lead to the same page of addbba.com.

If I delete the /etc/nginx/sites-enabled/addbba.com and leave only /etc/nginx/sites-enabled/matrixandcompany.com, the two URLs and 178.62.87.72 all lead to the same page of matrixandcompany.com.

So it seems that the URL is not well parsed and does not make any difference. Did I set something wrong in GoDaddy (maybe DNS?), or in nginx?

Thank you

1 Answer

If you take a closer look at one of the URL's source code, you will see that it contains the following:

<frameset rows="100%,*" border="0">
  <frame src="http://178.62.87.72" frameborder="0" />
  <frame frameborder="0" noresize />
</frameset>

This is because you have set up your domains to "forward" to your IP address. GoDaddy does that by hosting a page for you that loads http://178.62.87.72/. So, even if you browse to http://matrixandcompany.com, nginx will receive a request for 178.62.87.72 because of GoDaddy's forwarding.

You need to point the DNS records to your droplet instead of setting up forwarding. You can do that by either using GoDaddy's DNS Manager, or setting your domains' nameservers to DigitalOcean's.

The following tutorials should help you point your domains' nameservers to DigitalOcean's nameservers and configure the proper DNS records:

  1. How to Point to DigitalOcean Nameservers From Common Domain Registrars
  2. How To Set Up a Host Name with DigitalOcean
by Etel Sverdlov
This article walks you through setting up the DNS for your site. The tutorial includes steps to set up an A records, point your nameservers, and provides some information about MX records.
  • Thank you...

    I am a little bit confused about setting up the host name: I don't know which records to add.

    I have set up two domains screenshot. Here is the details of addbba

    Is it correct? At the moment it does not work, I don't know if it is just a time issue...

    Thanks

  • Yes, that is correct. :) Both domains are working fine now on my end, you might have to wait a bit until the new DNS settings propagate or try clearing your browser's and operating system's DNS cache if possible.

    If you need the www. subdomain as well, add the following record to each of the domains:

  • For the www subdomain, should it be a A record as here or a CNAME?

    Thank you

  • It should be a CNAME.

Have another answer? Share your knowledge.