Ivo The Master's picture

Hi there!

I've started Turnkey Lamp version, config everything.

I go in Webmin.

Then I've created 2 different "no-ip.org" address (example1.no-ip.org and example2.no-ip.org) linked to the same IP address (my router external IP, obviously).

Then I've setted in my Port Forwarding router panel the permission to access from the external to my Turnkey PC (192.168.1.75) with the port 80.

So, in Webmin, accessing to Apache Control Panel, I've created 2 different Name-based virtualhost.

When I tried them, I have always the "Turnkey LAMP Home Page" (the one with the 3 options clickables), with the example1 and with the example2.

Why Apache couldn't read the hostname request?

Thanks

Forum: 
L. Arnold's picture

I set up a name based secondary domain on one of my systems a while back.  It was working.  However last week I tested again and it was only resolving to the first domain.

So I am at the same place you are.  It could have been a change in the package, or something overwritten by TKLBAM but it appears in my Apache that the second host is still there.  It is just that Apache always responds as the first host when I try to go there.

Jeremy Davis's picture

Here's how I do it with 2 separate domains both configured to point to the same IP (ie the server IP, or the router IP with port forwarding, etc.

The 2 FQDNs I will use for this example are: stuff.example1.com & morestuff.example2.net

This example is assuming a clean/default TKL LAMP install. It will apply generally to other setups but that can't 100% be guaranteed. Also this is how I do it and it works - I'm not guaranteeing that this is the best or only way! :)

So let's get to it:

For starters create your first new 'site':

nano /etc/apache2/sites-available/stuff.example1.com

This will open a blank file for editing. Inside this file paste/type this:

<VirtualHost *:80>
        ServerName stuff.example1.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/stuff.example1.com/
        <Directory /var/www/stuff.example1.com/>
                Options Indexes FollowSymLinks MultiViews
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

Exit and save (<Ctrl><x>, <Enter>) and do the same with your second site (and subsequent sites):

nano /etc/apache2/sites-available/morestuff.example2.net
<VirtualHost *:80>
        ServerName morestuff.example2.net
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/morestuff.example2.net/
        <Directory /var/www/morestuff.example2.net/>
                Options Indexes FollowSymLinks MultiViews
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

 

Finally enable your 2 (or more) new sites and restart Apache.

a2ensite stuff.example1.com
a2ensite morestuff.example2.net
service apache2 restart

Notes:

  • If you have a static IP you can (and probably should) change out the * for your server WAN IP address
  • This configuration leaves the direct IP of your server available, and if someone browses to it, they will see your file heirarchy. There are a number of ways to avoid this.
    • Edit the default site: Change the DocumentRoot (and <Directory ...) in the default site to point to one of your other sites.
    • Another pretty easy way is to edit the /etc/apache2/sites/available/default site and comment out the DocumentRoot line as well as the whole <Directory /var/www/>stuff in here</Directory> section (this will give you a 404 - not found error page).
    • My favourite way is to just put a placeholder html file there:
      echo "<title>Move along...</title><h1><br>Move along please, <br><br> Nothing to see here..." > /var/www/index.html
    • You could use a .htaccess file to disable access to the doc root altogether.
    • Probably lots of other ideas...

Add new comment