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:
The virtual host configuration is the same for Debian/Ubuntu, but here's a link to the Debian 10 guide just in case:
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