TurnKey Linux Virtual Appliance Library

[LAMP] VirtualHost Name-Based

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

L. Arnold's picture

I worked through this 6 months ago, was working, but now not..

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.

I found the same

I found the same problem.

 

I have two sub domains,

www/sub1.domain.com and www/sub2.domain.com.  when I set two virtual hosts on port 80 of same ip, apache ignores host names, sub2.domain.com gets the contents of sub1.domain.com.

bug or configuration problem?  any1?

Jeremy's picture

Haven't tried with Webmin but can do manually

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...

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)