Default IP address to main domain?

Hi,

I have two domains on my Linode - domain1.com and domain2.com. All works fine. However when I enter the IP address of my Linode in the address bar it returns domain2.com - how do I make it return domain1.com?

One possible cause I've read is alphabetically domain2.com comes first in my conf files. Could I re-name the conf file 0domain2.com.conf and then just restart Apache or is it not as simple as that?

I thought between the rDNS and the host file being set as below it would solve it. The rDNS is set to domain2.com

127.0.0.1 localhost
actualIP domain2.com

--

Separately, if I SSH to domain1.com but want to change it to new.domain1.com (and no longer ssh to domain1.com), is it the host file I change?

Thanks,

Simon

3 Replies

Hi Simon! Renaming the .conf files may get results in some setups, but I've found the easiest way to do this is to just create a new .conf file that set the IP address itself as the host. Specifically, if you're using Apache, the ServerName variable should be the one you set to your Linode's IP address. That way, if anyone visits the IP address itself you can direct it to any document root you'd like.

We have a guide on virtual hosts in Apache on CentOS 8 here:

https://www.linode.com/docs/web-servers/apache/how-to-install-apache-web-server-centos-8/#configure-virtual-hosting

The virtual host configuration is the same for Debian/Ubuntu, but here's a link to the Debian 10 guide just in case:

https://www.linode.com/docs/web-servers/apache/how-to-install-apache-web-server-debian-10/#configure-virtual-hosting

For Nginx, we have a guide on virtual hosts here:

https://www.linode.com/docs/web-servers/nginx/how-to-configure-nginx/#name-based-virtual-hosting

As for the second question, yes editing the /etc/hosts file would work. Otherwise ssh will just use the IP address that resolves for the given domain.

Hi,

Thanks for the reply.

I made a file called ip.conf with the following…

 <VirtualHost *:80>
 ServerAdmin <email>
 ServerName ip.ip.ip.ip
 DocumentRoot /var/www/domain1.com/public_html/
 ErrorLog /var/www/domain1.com/logs/error.log
 CustomLog /var/www/domain1.com/logs/access.log combined
 </VirtualHost>

But when I execute a2ensite ip.conf I get the following…

ERROR: Site ip does not exist!

So instead I have modified the domain1.com.conf file to this…

    <VirtualHost *:80>
    # Admin email, server name (domain name), and any aliases
    ServerAdmin <email>
    ServerName domain1.com
    ServerAlias www.domain1.com ip.ip.ip.ip

    # Index file and document root (where the public files are located)
    DirectoryIndex index.html index.php
    DocumentRoot /var/www/html/domain1.com/public_html
    # Log file locations
    LogLevel warn
    ErrorLog /var/www/html/domain1.com/log/error.log
    CustomLog /var/www/html/domain1.com/log/access.log combined
    </VirtualHost>

It does the job, but is it safe/OK to do it like this?

--

Secondly, I changed the /etc/hosts and /etc/hostname to new.domain1.com but I could not SSH to new.domain1.com - do I need to add new.domain1.com as an alias in domain1.com.conf too? Or maybe as an official subdomain in the Linode control panel?

Many thanks,

Simon

Sorry I realised I was making the ip.conf file in sites-enabled rather than sites-available. Doing it in sites-available and then a2ensite ip.conf didn't give any errors so should be OK.

I've removed the IP alias in the domain1.com.conf file to revert it to normal.

Thanks,

Simon

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct