Hosting multiple websites with Apache2

Posted by Steve on Thu 6 Jul 2006 at 22:03

One of the most common Apache2 questions I've seen on Debian mailing lists is from users who wonder how to host multiple websites with a single server. This is very straightforward, especially with the additional tools the Debian package provides.

We've previously discussed some of the tools which are included in the Apache2 package, but what we didn't do was show they're used from start to finish.

There are many different ways you can configure Apache to host multiple sites, ranging from the simple to the complex. Here we're only going to cover the basics with the use of the NameVirtualHost directive. The advantage of this approach is that you don't need to hard-wire any IP addresses, and it will just worktm. The only thing you need is for your domain names to resolve to the IP address of your webserver.

For example if you have an Apache server running upon the IP address 192.168.1.1 and you wish to host the three sites example.com, example.net, and example.org you'll need to make sure that these names resolve to the IP address of your server.

(This might mean that you need example.com and www.example.com to resolve to the same address. However that is a choice you'll need to make for yourself).

Since we'll be hosting multiple websites on the same host it makes a lot of sense to be very clear on the location of each sites files upon the filesystem. The way I suggest you manage this is to create a completely seperate document root, cgi-bin directory, and logfile directory for each host. You can place these beneath the standard Debian prefix of /var/www or you may use a completely different root - I use /home/www.

If you've not already done create the directories to contain your content, etc, as follows:

root@irony:~# mkdir /home/www

root@irony:~# mkdir /home/www/www.example.com
root@irony:~# mkdir /home/www/www.example.com/htdocs
root@irony:~# mkdir /home/www/www.example.com/cgi-bin
root@irony:~# mkdir /home/www/www.example.com/logs

root@irony:~# mkdir /home/www/www.example.net 
root@irony:~# mkdir /home/www/www.example.net/htdocs
root@irony:~# mkdir /home/www/www.example.net/logs
root@irony:~# mkdir /home/www/www.example.net/cgi-bin

root@irony:~# mkdir /home/www/www.example.org 
root@irony:~# mkdir /home/www/www.example.org/htdocs
root@irony:~# mkdir /home/www/www.example.org/logs
root@irony:~# mkdir /home/www/www.example.org/cgi-bin

Here we've setup three different directory trees, one for each site. If you wanted to have identical content it might make sense to only create one, and then use symbolic links instead.

The next thing to do is to enable virtual hosts in your Apache configuration. The simplest way to do this is to create a file called /etc/apache2/conf.d/virtual.conf and include the following content in it:

#
#  We're running multiple virtual hosts.
#
NameVirtualHost *

(When Apache starts up it reads the contents of all files included in /etc/apache2/conf.d, and files you create here won't get trashed on package upgrades.)

Once we've done this we can create the individual host configuration files. The Apache2 setup you'll find on Debian GNU/Linux includes two directories for locating your site configuration files:

/etc/apache2/sites-available

This contains configuration files for sites which are available but not necessarily enabled.

/etc/apache2/sites-enabled

This directory contains site files which are enabled.

As with the conf.d directory each configuration file in the sites-enabled directory is loaded when the server starts - whilst the files in sites-available are completely ignored.

You are expected to create your host configuration files in /etc/apache2/sites-available, then create a symbolic link to those files in the sites-enabled directory - this will cause them to be actually loaded/read.

Rather than actually messing around with symbolic links the Debian package includes two utility commands a2ensite and a2dissite which will do the necessary work for you as we will demonstrate shortly.

Lets start with a real example. Create /etc/apache2/sites-available/www.example.com with the following contents:

#
#  Example.com (/etc/apache2/sites-available/www.example.com)
#
<VirtualHost *>
        ServerAdmin webmaster@example.com
        ServerName  www.example.com
        ServerAlias example.com

        # Indexes + Directory Root.
        DirectoryIndex index.html
        DocumentRoot /home/www/www.example.com/htdocs/

        # CGI Directory
        ScriptAlias /cgi-bin/ /home/www/www.example.com/cgi-bin/
        <Location /cgi-bin>
                Options +ExecCGI
        </Location>


        # Logfiles
        ErrorLog  /home/www/www.example.com/logs/error.log
        CustomLog /home/www/www.example.com/logs/access.log combined
</VirtualHost>

Next create the file www.example.net:

#
#  Example.net (/etc/apache2/sites-available/www.example.net)
#
<VirtualHost *>
        ServerAdmin webmaster@example.net
        ServerName  www.example.net
        ServerAlias example.net

        # Indexes + Directory Root.
        DirectoryIndex index.html
        DocumentRoot /home/www/www.example.net/htdocs/

        # CGI Directory
        ScriptAlias /cgi-bin/ /home/www/www.example.net/cgi-bin/
        <Location /cgi-bin>
                Options +ExecCGI
        </Location>


        # Logfiles
        ErrorLog  /home/www/www.example.net/logs/error.log
        CustomLog /home/www/www.example.net/logs/access.log combined
</VirtualHost>

Finally create the file www.example.org:

#
#  Example.org (/etc/apache2/sites-available/www.example.org)
#
<VirtualHost *>
        ServerAdmin webmaster@example.org
        ServerName  www.example.org
        ServerAlias example.org

        # Indexes + Directory Root.
        DirectoryIndex index.html
        DocumentRoot /home/www/www.example.org/htdocs/

        # CGI Directory
        ScriptAlias /cgi-bin/ /home/www/www.example.org/cgi-bin/
        <Location /cgi-bin>
                Options +ExecCGI
        </Location>


        # Logfiles
        ErrorLog  /home/www/www.example.org/logs/error.log
        CustomLog /home/www/www.example.org/logs/access.log combined
</VirtualHost>

Now we've got:

  • Three directories which can be used to contain our content.
  • Three directories which can be used to contain our logfiles.
  • Three directories which can be used to contain our dynamic CGI scripts.
  • Three configuration files which are being ignored by Apache.

To enable the sites simply run:

root@irony:~# a2ensite www.example.com
Site www.example.com installed; run /etc/init.d/apache2 reload to enable.

root@irony:~# a2ensite www.example.net
Site www.example.net installed; run /etc/init.d/apache2 reload to enable.

root@irony:~# a2ensite www.example.org
Site www.example.org installed; run /etc/init.d/apache2 reload to enable.

This will now create the symbolic links so that /etc/apache2/sites-enabled/www.example.org, etc, now exist and will be read.

Once we've finished our setup we can restart, or reload, the webserver as the output above instructed us to do with:

root@irony:~# /etc/init.d/apache2 reload
Reloading web server config...done.
root@irony:~# 

 

 


Posted by trollll (64.128.xx.xx) on Thu 6 Jul 2006 at 23:19
[ View Weblogs ]

I found it very easy to add webmail to all domains given this sort of setup, by adding the following to each conf:

        ServerAdmin webmaster@example.org
        ServerName  webmail.example.org

        # Indexes + Directory Root.
        DirectoryIndex index.html
        DocumentRoot /home/www/www.example.org/webmail/

        # Logfiles
        ErrorLog  /home/www/www.example.org/logs/error.log
        CustomLog /home/www/www.example.org/logs/access.log combined

Then, you can install Horde (for example, as I did) in /home/www/webmail, have it use the hostname as part of the login, and make a symbolic link by doing the following:

$ ln -s /home/www/webmail /home/www/www.example.org/webmail

I made symbolic links rather than defining the path directly in the conf, because that way I can easily change webmails without restarting the server. Especially handy if a few domains should have a different set of modules enabled or use different authentication methods, etc.

[ Parent | Reply to this comment ]

Posted by Anonymous (193.195.xx.xx) on Fri 7 Jul 2006 at 08:51
Can you not just use Alias as part of the main config to achieve the same thing?

And you can just reload the server instead of restarting it if you change the config.

[ Parent | Reply to this comment ]

Posted by trollll (24.153.xx.xx) on Sat 8 Jul 2006 at 18:21
[ View Weblogs ]
Can you not just use Alias as part of the main config to achieve the same thing?

You could, but I don't like having webmail as (essentially) a subdirectory. Also, this way you can apply different configurations to each webmail as necessary.

And you can just reload the server instead of restarting it if you change the config.

Heh...I haven't used reload in so long after having odd behavior early on that I forgot about it completely. I don't restart webservers often so it doesn't come up a whole lot.

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Fri 7 Jul 2006 at 09:19
[ View Steve's Scratchpad | View Weblogs ]

I guess with that setup, since the webmail is "inside" the document root you can access it either via either of the links:

  • webmail.example.org
  • www.example.org/webmail

For me I'd tend to only use the webmail.example.org site available and I'd do it with:

mkdir /home/www/webmail.example.org/
mkdir /home/www/webmail.example.org/logs

ln -s /home/www/webmail /home/www/webmail.example.org/htdocs

(No need for a CGI directory in this case I guess!)

Still I guess this is personal preference really..

Steve

[ Parent | Reply to this comment ]

Posted by trollll (64.128.xx.xx) on Fri 7 Jul 2006 at 14:18
[ View Weblogs ]
Yeah, it just comes down to personal preference - I just like having the logs, etc. in the same directory for a domain (just different prefixes when it comes to the logs).

With a webmail document root of /home/www/www.example.org/webmail/ it would sit outside of the /home/www/www.example.org/htdocs/ directory, though. I wouldn't want the overlap either.

[ Parent | Reply to this comment ]

Posted by cfry (68.170.xx.xx) on Fri 7 Jul 2006 at 02:38
It can be even simpler than that. You can configure apache once, then add domain directories on the fly with something like:

UseCanonicalName Off
VirtualDocumentRoot /var/www/%0/public_html
VirtualScriptAlias /var/www/%0/cgi-bin

as explained in detail at http://httpd.apache.org/docs/2.0/vhosts/mass.html

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Fri 7 Jul 2006 at 08:59
[ View Steve's Scratchpad | View Weblogs ]

Like I said there are multiple ways to do this and using your method is a neat approach if you have lots of simple sites which don't need anything special.

The advantage of the method shown here is that it allows you to customize each different site very easily, (since there is a configuration file for each host), that might allow you to do things like install mailman on one host, and add custom redirects, etc.

In my server I have around 10 domains, and each has different customizations - for example the configuration file for this site enables lots of mod_rewrite magic so that all our URLs are pretty - but I don't want those customisations applied globally which I think I would have to do if I used the mass-virtual hosting you suggest.

Steve

[ Parent | Reply to this comment ]

Posted by cfry (128.2.xx.xx) on Fri 7 Jul 2006 at 12:35
I personally use both. I have the generic configuration for anyone who doesn't need anything special, then on top of that I add custom VirtualHost sections for anyone who needs more. The small difference is that the VirtualHost sections don't need to redefine DocumentRoot and ScriptAlias. Also, because of the generic Virtual Root and Alias settings, each VirtualHost can use ServerAlias to configure the same configuration settings for physically different websites. For example, the mailing lists for all of my domains are all simultaneously configured with:
   <VirtualHost *:80>
       ServerName lists.example.com
       ServerAlias lists.*

       RedirectMatch permanent ^/$ /mailman/listinfo

       RewriteEngine on
       RewriteRule ^/mailman(/.*)?$ /cgi-bin/mailman$1 [PT,L]
   </VirtualHost>

[ Parent | Reply to this comment ]

Posted by trakic (130.226.xx.xx) on Fri 7 Jul 2006 at 13:45
[ View Weblogs ]
To cfry: - How do you achieve that (customize VirtualHost sections on top of dyn mass virtual hosting)? - Is it possible with Apache 1.3? My dyn mass virtual hosting work ok, but I want to constumize them accordingly. My last lines httpd.conf:
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
VirtualDocumentRoot /Library/WebServer/Hosts/%0/Documents
VirtualScriptAlias /Library/WebServer/Hosts/%0/CGI-Executables
- My costumised virtual host bits are like this:

VirtualHost
   ServerName          svn.domain.ltd
    ServerAlias         svn
    RewriteEngine On
    Redirect            /       http://10.0.0.0:8080/
    #ProxyPreserveHost   On
    #ProxyPass           /       http://10.0.0.0:8080/
    #ProxyPassReverse    /       http://10.0.0.0:8080/
VirtualHost
On my error log I still get like:
... File does not exist: /Library/WebServer/Hosts/svn.domain.tld/Documents/
- Any hints? Regards Admir ~

[ Parent | Reply to this comment ]

Posted by cfry (128.2.xx.xx) on Fri 7 Jul 2006 at 14:22
You still need to manually create the directories (in your case /Library/WebServer/Hosts/svn.domain.tld/Documents/ ).

[ Parent | Reply to this comment ]

Posted by Anonymous (213.164.xx.xx) on Fri 7 Jul 2006 at 08:19
This setup breaks under php safe mode. You want to use /var/www for holding the sites.

[ Parent | Reply to this comment ]

Posted by Anonymous (193.195.xx.xx) on Fri 7 Jul 2006 at 08:52
Just change your DocumentRoot to /home

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Fri 7 Jul 2006 at 09:15
[ View Steve's Scratchpad | View Weblogs ]

I tend to regard PHPs safe mode as still-broken.

For my PHP I use mod_security/mod_ifier + suphp.

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (213.164.xx.xx) on Fri 7 Jul 2006 at 11:48
I don't mean php safe mode. Oops. I mean suexec.

[ Parent | Reply to this comment ]

Posted by Anonymous (202.7.xx.xx) on Mon 24 Jul 2006 at 05:00
Nice article. I had been looking for a clear, non confusing howto on this for ages, but had no luck until I found this one. Thanks Steve!

I've got two concerns though:
1) when users enter blahblahblah.example.com, they get taken to the directory above the htdocs directory, with access to log files and stuff, which is somewhat of a security hole. How do you close that one off?

2) I get the following warning when I restart apache (I'm running Apache 2.0.55):

[warn] NameVirtualHost *:0 has no VirtualHosts

How do I make the warning go away?

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Mon 24 Jul 2006 at 06:39
[ View Steve's Scratchpad | View Weblogs ]

For your first question I'm unsure - I can't see how that could ever happen in the setup I described. Each site is only "example.com", or "www.example.com" - the name "blahblah.example.com" wouldn't even resolve, and if it did shouldn't be visible - unless you have a default virtual host setup for /var/www and you're storing your sites beneath that?

In that case move the virtual hosts beneath /home/www, like I do, or comment out the default entry.

For the second I'd just remove the line "NameVirtualHost *:0" since it isn't relevant.

Run "rgrep -li NameVirtualHost /etc/apache2" to find where it is set.

Steve

[ Parent | Reply to this comment ]

Posted by xoctor (202.7.xx.xx) on Mon 24 Jul 2006 at 15:36
Yep - forgot to disable the default account! Removing the default account fixed the warning, but now going to 'http://something.example.com' produces a very odd result. I have 3 virtual domains, say alpha.com, beta.com and delta.com. If I point my browser at nonsense.alpha.com (or nonsense.beta.com) I get the delta.com directory. alpha.com and www.alpha.com work as expected. btw - they're all defined under /home/www

[ Parent | Reply to this comment ]

Posted by Steve (80.68.xx.xx) on Mon 24 Jul 2006 at 15:43
[ View Steve's Scratchpad | View Weblogs ]

I think that what is happening is that the host you're requesting is pointed to the IP of the server, but you don't have a virtual setup explicity setup for it.

So instead Apache passes it to the first available virtual host (ie. the file in /etc/apache2/sites-enabled which is first will be used.)

To fix this either:

  • Add a new ServerAlias to the relevant file.
  • Ensure that 00-default is used for the site which you wish to be used for unknown hosts.

Really I can't see this being a problem in general since people don't often use wildcard dns.

I'd suggest you add the folloing to www.alpha.com:

ServerName www.alpha.com
ServerAlias alpha.com
ServerAlias *.alpha.com

That will ensure that blah.alpha.com is handled by the Alpha.com virtual host. Add similar wildcard settings to beta.com, etc.

Steve

[ Parent | Reply to this comment ]

Posted by xoctor (202.7.xx.xx) on Mon 24 Jul 2006 at 16:14
Thanks for your help Steve. Now I'm cookin' with gas!

[ Parent | Reply to this comment ]

Posted by gmcneal (66.92.xx.xx) on Wed 6 Sep 2006 at 02:01
I created four virtual websites on a single server as outlined in the article.
The sites show up as expected on Win2k OS, but only the default site
displays on my Linux(Ubuntu distribution) OS.
The results are the same with IE and Firefox.
The URLs are of the format http://example.com, http://website1.example.com,
http://website2.example.com, http://website3.example.com, etc.
http://example.com is the default.

I must be missing something simple.

[ Parent | Reply to this comment ]

Posted by Anonymous (219.64.xx.xx) on Fri 22 Jul 2011 at 11:25
Hope all your 4 websites are giving different results. Actually, I also want to do similar. But I can't use "NameVirtualHost *", its giving error. Currently I am running two websites. One at openssl configured and other running at virtual host. I want to add one more website in the virtual host. How I will do that please guide me.

[ Parent | Reply to this comment ]

Posted by sphaero (83.160.xx.xx) on Wed 20 Sep 2006 at 15:56
[ View Weblogs ]
To enable virtual hosts using the default debian setup make sure the default site in /etc/apache2/sites-available contains a ServerName directive containing the hostname of your server. That's the only thing that needs to be edited to get virtual hosts working correctly on Debian Sarge.

It makes me wonder why it's not setup by the debian installer of apache2.

[ Parent | Reply to this comment ]

Posted by jimbabwe (69.140.xx.xx) on Sun 24 Sep 2006 at 04:02
I've used this site a number of times; it's great.

Had a slight issue with a2ensite.

In working with Apache 2.0.54 on Debian 2.6.8-3-686-smp, I couldn't get a2ensite to run as shown above.

I followed all instructions, but when I ran a2ensite as shown in the example "a2ensite www.example.com" (putting in my site, of course, the message came back "This site does not exist!"

I tried next to run the a2ensite command alone, without any additional info. behind the command (i.e., just typed 'a2ensite' as root) and it worked fine, prompting me for information and at the end, enabled the site.

Thanks again for the help!

[ Parent | Reply to this comment ]

Posted by Anonymous (165.155.xx.xx) on Mon 19 Mar 2007 at 16:49
thank you jimbabwe. I had to do that too.

[ Parent | Reply to this comment ]

Posted by pvince (70.60.xx.xx) on Mon 22 Feb 2010 at 16:49
I have a problem with the a2ensite command too. I comes up as "command not found" for me. I'm running Apache2 on Fedora 12

[ Parent | Reply to this comment ]

Posted by Anonymous (190.148.xx.xx) on Fri 2 Apr 2010 at 18:05
Hi. I'm cancuengt.
Debian (and based distros) has a very special way to handle virtual hosts with apache2. This is not the same with Fedora (and based distros). I recommend that you visit http://www.mjmwired.net/resources/mjm-apache-virtual-sites.html. This might help you.
Greetings.

[ Parent | Reply to this comment ]

Posted by olden (193.34.xx.xx) on Sun 29 Apr 2007 at 17:05
[ View Weblogs ]
I would like to share scenario for Perl
that can help in the virtual domain for Apache2.
Indeed the script:
=====================
#!/usr/bin/perl -w

use strict;
use English;

my $etc = "/etc/apache2/sites-available/";
my $log = "/var/log/apache2/";
my $www = "/var/";
my $a2ensite = "/usr/sbin/a2ensite";
my $a2 = "/etc/init.d/apache2";
my ($login,$pass,$uid,$gid) = getpwnam("www-data");

exit unless defined @ARGV;
my $site = $ARGV[0];
my $wwwsite = "www.".$site;

open FTEMPLATE, "<$etc/TEMPLATE" or die "Can't open file: $!\n";
my @tmpl = <FTEMPLATE>;
close FTEMPLATE;

mkdir "$log$wwwsite", 0755;
mkdir "$www$wwwsite", 0755;
chown $uid, $gid, "$www$wwwsite";

open FSITE, ">$etc$wwwsite" or die "Can't write file: $!\n";
foreach (@tmpl) {
s!<SITE>!$site!g;
print FSITE;
}
close FSITE;

open FTIINDEX, "<$etc/TINDEX" or die "Can't open file: $!\n";
open FOIINDEX, ">$www$wwwsite/index.php" or die "Can't write file: $!\n";
while (<FTIINDEX>) { print FOIINDEX }
close FOIINDEX;
close FTIINDEX;
chown $uid, $gid, "$www$wwwsite/index.php";

system($a2ensite,$wwwsite);
system($a2,"reload");
=====================

Template TEMPLATE:
=====================
#
# <SITE> (/etc/apache2/sites-available/www.<SITE>)
#
<VirtualHost *>
ServerAdmin postmaster@olympus.net.ua
ServerName www.<SITE>
ServerAlias <SITE>
DirectoryIndex index.html index.htm index.php
DocumentRoot /var/www.<SITE>/
ErrorLog /var/log/apache2/www.<SITE>/error.log
CustomLog /var/log/apache2/www.<SITE>/access.log combined
</VirtualHost>
=====================

Template TINDEX:
=====================
<html>
<head>
<title><?=$_SERVER["HTTP_HOST"]?></title >
</head>
<body>
The web server <?=$_SERVER["HTTP_HOST"]?>
is not available or under development.<br>
For more information contact
<a href="mailto:<?=$_SERVER["SERVER_ADMIN"]?>">;
<?=$_SERVER["SERVER_ADMIN"]?></a>.<br> ;
</body>
</html>
=====================

Indeed all.

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Sun 29 Apr 2007 at 17:38
[ View Steve's Scratchpad | View Weblogs ]

Not bad.

I have something similar for adding, removing, and listing sites for Apache2 and mail handling with Exim4... :)

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (15.195.xx.xx) on Thu 17 May 2007 at 08:24
Hi,

I have followed you tutorial and I get this...:

Keeper:/home# /etc/init.d/apache2 reload
Reloading web server config...2464
apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.0.187 for ServerName
[Thu May 17 10:01:40 2007] [warn] NameVirtualHost *:0 has no VirtualHosts
.
the server's ip adress is 192.168.0.187 (it's behind a router that forwardes needed ports to this machine)

any suggestion ?

[ Parent | Reply to this comment ]

Posted by roncarney (24.120.xx.xx) on Thu 21 Jun 2007 at 19:20
I get the same msg, as well, except instead of the box's IP I get the loopback. But I do get the
[Thu May 17 10:01:40 2007] [warn] NameVirtualHost *:0 has no VirtualHosts
msg and nothing is web accessible, I just get a timeout in the browser.

Any Help?

[ Parent | Reply to this comment ]

Posted by Anonymous (76.177.xx.xx) on Wed 11 Jul 2007 at 07:09
For the record I am using Ubuntu Feisty Fawn to do all of this.

I followed the tutorial and but did this for my sites-available instead. I have 6 sites set up and all work. I still however get the same message as you. the message indicates that your using the wildcard instead of an IP address. If you used this you shouldn't need to create the /etc/apache2/conf.d/virtual.conf


NameVirtualHost *
#
# Example.com (/etc/apache2/sites-available/www.example.com)
#
<VirtualHost *>
ServerAdmin admin@example.com
ServerName example.com
# Putting *. in front of the name of the website makes things like webmail or www work
ServerAlias *.example.com

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/www/example/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/example/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>


# Logfiles
ErrorLog /var/www/example/logs/error.log
CustomLog /var/www/example/logs/access.log combined
</VirtualHost>

[ Parent | Reply to this comment ]

Posted by Anonymous (78.144.xx.xx) on Sun 25 Nov 2007 at 18:39
Hi i have done a little guide on this using the virtual.con in apache conf folder and it works flawlessly with no errors.

check it out at http://brandan.no-ip.info/forum/ i have just started the forum so i can keep all my tips and tricks but everyone is welcome to put up some tuts to help out. AND THANKS TO THE GUY WHO MADE THIS TUTORIAL AND ALL OTHER TUTORIALS.

[ Parent | Reply to this comment ]

Posted by cvtrig (74.10.xx.xx) on Wed 9 Jan 2008 at 05:59
So let me ask:

If I'm on a local intranet, as I'm setting up a server for my lab to use a wiki for documentation purposes.

I've had our IT Dept reserve the IP on their WINS box so that the internal IP resolves to the URL http://wiki

Since I'm not dealing with FQDN, and not using www or .com, do I just use an IP address or the name of the server itself?

I see the configuration you have but when I try to do that without the FQDN or www or .com or I get the error that no virtual hosts can be found.

Any ideas? Since this is on an internal intranet, will this even work without a FQDN?

Many thanks in advance.

cvtrig

[ Parent | Reply to this comment ]

Posted by Anonymous (213.140.xx.xx) on Fri 11 Jan 2008 at 15:02
I had the same message and some (not all) of my virtual hosts weren't accessible. What worked for me:
1. disable the default host - a2dissite default
2. make sure that only one NameVirtualHost * is included in your configuration. On ubuntu server I placed
NameVirtualHost *
right before
Include /etc/apache2/sites-enabled/
found at the end of /etc/apache2/apache2.conf, and removed all NameVirtualHost * lines from files in /etc/apache2/sites-enabled
3. reload apache2 /etc/init.d/apache2 reload

[ Parent | Reply to this comment ]

Posted by Anonymous (208.17.xx.xx) on Fri 19 Feb 2010 at 09:07
Thank you so much. I am using Ubuntu 8.04LTS Apache 2.2. I only had one hair left to pull out until I found your post. Everything works now. Thanks again!!!

[ Parent | Reply to this comment ]

Posted by Anonymous (87.184.xx.xx) on Tue 12 Jul 2011 at 00:12
Thank you so much for your solution. Everything works fine now. This has helped me a lot! Thank you!

[ Parent | Reply to this comment ]

Posted by Anonymous (83.71.xx.xx) on Fri 4 Jan 2013 at 14:46
On LinuxMint Debian this solved my issue as NameVirtualHosts were not being found. Thank you.

[ Parent | Reply to this comment ]

Posted by tltan88 (218.111.xx.xx) on Sat 12 Jan 2008 at 02:39
Everything worked fine for my two sites. But the first site would
not read firstsite.com but when I typed www.firstsite.com
it showed my index.html page. The second site, I had no
problems at all. The first site showed error message of: The requested URL/apache2-default/was not found on the server. What did I do wrong?

[ Parent | Reply to this comment ]

Posted by Steve (82.32.xx.xx) on Sat 12 Jan 2008 at 15:13
[ View Steve's Scratchpad | View Weblogs ]

Probably you forgot the alias. Something like this:

<VirtualHost *>
        ServerName  firstsite.com
        ServerAlias www.firstsite.com
        ...
        ...

Failing that is that you forgot to delete the 000-default site which is enabled.

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (213.100.xx.xx) on Sat 2 Feb 2008 at 23:25
Thanks for the article, short and clear as usual. However I am still a bit confused about my server configuration. Untill today I didn't have a registered domain name, I just published a few pages for friends and family...these pages were accessed as http://my.server.ip.addr/pageX/
These pages were located in /var/www , like /var/www/pageX/ and in /etc/apache2/sites-available/ I have created a file for each page by just copying the default file which was there from the very beginning, like this:
$cp default pageX

and I didn't edit these files at all.

in the /etc/apache2/sites-enabled/ I have only one symlink:
000-default -> /etc/apache2/sites-available/default

In apache2.conf I didn't find the NameVirtualHost directive, but I saw I have this:
Include /etc/apache2/sites-enabled/

the server is behind a router, its IP is 192.1681.6 and it has

nameserver 192.168.1.1

in the /etc/resolv.conf file (192.168.1.1 is of course the IP of the router)

in /etc/hosts I have this:
127.0.0.1 localhost
192.168.1.6 monica.mcrae monica


...I think these are the details. Now my questions.

Fisrt, why the pages are accessible though their configurations files are in sites-available instead in sites-enabled?

Is Include /etc/apache2/sites-enabled/ in apache2.conf substituting (in a way) the NameVirtualHost directive (which presents in each page conf file in sites-available).

And the most important - today I've bought a domain name and I want to host it on my server. I this howto enough..I mean the virtual host configuration is more or less clear for me, but what about /etc/hosts and /etc/resolv.conf files. Do I have to set something different in them.

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Mon 31 Mar 2008 at 22:26
Great example.
But i have the following issue:
i want to create a lot of subdomains with keywords. etc. keyword1.mysite.com , keyword2.mysite.com, keyword3.mysite.com, keyword4.mysite.com, etc.


If i use both methods list on the site with this: ServerAlias *.mysite.com

I would still have to create a link to the real web directory, is there another way of doing this ??? that i do not have to create so many soft links back to the original web direcotory ???
thanks
mjh

[ Parent | Reply to this comment ]

Posted by Steve (82.32.xx.xx) on Mon 31 Mar 2008 at 22:41
[ View Steve's Scratchpad | View Weblogs ]

If the keywords all point at the same directory then you could do it without having to make any symlinks. Just use a config file like this:

<VirtualHost>
  ServerName mysite.com
  ServerAlias *.mysite.com
  ..
  DocumentRoot /home/www/mysite.com/

You just need to add the DNS entries and it will work as expected.

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (72.89.xx.xx) on Mon 31 Mar 2008 at 23:09
i did try this but it seems not to work for me.

my www.mysite.com file looks like this:

<VirtualHost *>
ServerAdmin webmaster@mysite.com
ServerName mysite.com
ServerAlias *.mysite.com

# Indexes + Directory Root.
DirectoryIndex index.php index.html
DocumentRoot /var/www/html/websites/mysite.com/public_html/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/html/websites/mysite.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>


# Logfiles
ErrorLog /var/log/apache2/www.mysite.com/logs/error.log
CustomLog /var/log/apache2/www.mysite.com/logs/access.log combined
</VirtualHost>





I get this in the error log :
File does not exist: /var/www/html/websites/www.mysite.com

i get this on the webpage:
Not Found

The requested URL / was not found on this server.
Apache/2.2.3 (Debian) mod_python/3.2.10 Python/2.4.4 PHP/5.2.0-8+etch10 mod_perl/2.0.2 Perl/v5.8.8 Server at www.mysite.com Port 80




[ Parent | Reply to this comment ]

Posted by Steve (82.32.xx.xx) on Mon 31 Mar 2008 at 23:19
[ View Steve's Scratchpad | View Weblogs ]

The obvious question: Your error says:

File does not exist: /var/www/html/websites/www.mysite.com

Does it? If not make it via :

mkdir -p /var/www/html/websites/www.mysite.com
echo "test" >> /var/www/html/websites/www.mysite.com/index.html

Steve

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Mon 31 Mar 2008 at 23:53
i am sorry..but i am loosing you...

I get the error:

File does not exist: /var/www/html/websites/www.mysite.com


because in the browser i types WWW.mysite.com


i also get this error:

File does not exist: /var/www/html/websites/rid.mysite.com

again...because i typed in RID.mysite.com


and that is why it is not working ---once i create a soft link to the main dir --it works no problems. I have the * wildcard in the file..but no affect..

I must be missing something reall simple here :)

thanks
mjh

[ Parent | Reply to this comment ]

Posted by Steve (82.32.xx.xx) on Mon 31 Mar 2008 at 23:59
[ View Steve's Scratchpad | View Weblogs ]

If you have the configuration file as you suggested above you shouldn't be seeing this error.

You shouldn't have *any* other virtual hosts defined for mysite.com - just the one with the "*" in it. Did you leave the old ones in place?

If so remove them, and restart Apache2.

Steve

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Tue 1 Apr 2008 at 02:04
can it be the .htaccess file that is causing an issue ?
i am running joomla.with sef option enabled...is something special that has to be part of the htacces file.???
thanks
mjh

[ Parent | Reply to this comment ]

Posted by Steve (80.68.xx.xx) on Tue 1 Apr 2008 at 10:49
[ View Steve's Scratchpad | View Weblogs ]

Could be, I don't know.

I know that if the configuration file that you've pasted is the only configuration file, and you're not using any mass-hosting modules it should work as expected - it does for me.

I guess you'll need to ask for assistance on the debian-user mailing list.

Steve

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Tue 1 Apr 2008 at 15:45
i copied in a fresh new apache2.conf configuration file...very generic.

I got the following error below, could this have something to do with my problem ????



Forcing reload of web server (apache2)...apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.X.XX for ServerName
waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.X.XX for ServerName


thanks
mjh

[ Parent | Reply to this comment ]

Posted by Steve (80.68.xx.xx) on Tue 1 Apr 2008 at 16:02
[ View Steve's Scratchpad | View Weblogs ]

Add 'ServerName mysite.com' to a file /etc/apache2/conf.d/local and restart and all will be well.

Steve

[ Parent | Reply to this comment ]

Posted by peopleunit (70.249.xx.xx) on Wed 22 Jul 2009 at 23:15
I followed this step and in doing so it got rid of the Apache startup error that many others were having...

"Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName"

Now I get a clean error free startup... :-)

[Wed Jul 22 17:00:34 2009] [notice] Graceful restart requested, doing restart
[Wed Jul 22 17:00:34 2009] [notice] Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch configured -- resuming normal operations

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Mon 31 Mar 2008 at 23:55
if i make this directory...i will defeat the purpose...i do not want to create soft link directories.
thanks
mjh

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Tue 1 Apr 2008 at 00:15
i am still getting the same error.
If i create the dir, i do not get the error.
could there be an issue with the virtual.conf ???
can there be anything special in the main apache.conf file that i have to check??

thanks
mjh

[ Parent | Reply to this comment ]

Posted by mjh2000 (72.89.xx.xx) on Tue 1 Apr 2008 at 00:15
i am still getting the same error.
If i create the dir, i do not get the error.
could there be an issue with the virtual.conf ???
can there be anything special in the main apache.conf file that i have to check??

thanks
mjh

[ Parent | Reply to this comment ]

Posted by Anonymous (24.219.xx.xx) on Tue 27 May 2008 at 08:07
Hosting multiple sub-domains:

Hello everyone, great article and it worked very well for me except that I have three total sites:

1) www.my-domain.com
2) something.my-domain.com
3) www.another-domain.com

Both 1 and 3 worked well just by following this tutorial but I was unable to get number 2 to work. My problem was that I had added a CNAME entry pointing to my my-domain.com instead of an "A" record pointing to the actual IP address. After I changed it, it worked like a charm.

Also another tip: Whatever you put as the argument to the NameVirtualHost MUST be the same as what you put as the argument to VirtualHost in the .conf files.

I hope this helps someone else who has the same problems.

[ Parent | Reply to this comment ]

Posted by Anonymous (80.193.xx.xx) on Wed 13 Aug 2008 at 17:06
Hi I followed these instructions, they are the best Ive come across.
I have a ubuntu lamp server, ubuntu client on a local network.
everything worked except I couldnt call www.mikespoetry.com, it was the default on the server so came up anyway. my other site just wasnt showing.

add 192.168.1.5 www.mikespoetry.com
and 192.168.1.5 www.suze-an.com

to both the server and client hosts files and everything works including php

so thank you for stopping my head bleeding from all the cratching

michael

mikejenkinson@yahoo.com

im away to try and set up email now

[ Parent | Reply to this comment ]

Posted by Anonymous (86.134.xx.xx) on Sat 20 Dec 2008 at 23:24
I'm giving up

Right loads of virtual hosts BUT

[Sat Dec 20 23:05:42 2008] [error] (13)Permission denied: could not open transfer log file /lalrlalrlalala

or the Errorlog !!

I;ve switch to the apache user id and can create file in the logs direcorty

But apache still wont work !!!!!!!!!


AAAAAAAAARRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

Giz

[ Parent | Reply to this comment ]

Posted by Anonymous (134.58.xx.xx) on Mon 9 Feb 2009 at 13:19
Hi All,

I have another little problem with multiple sites configuration.

I have setup 2 sites. Everything works fine.
e.g. I have www.example.com and www.example.org set.

But now, if I want to load for example graphics from another directory.

eg. www.example.com/gfx/1.jpg

Than apache does not find the directory gfx although it is in the home directory of www.example.com.

anyone any idea how to fix this?

warm regards

[ Parent | Reply to this comment ]

Posted by Anonymous (71.196.xx.xx) on Sat 28 Feb 2009 at 14:11
I get this output when reloading:

sudo /etc/init.d/apache2 reload
* Reloading web server config apache2 [Sat Feb 28 09:06:27 2009] [error] VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
[Sat Feb 28 09:06:27 2009] [warn] NameVirtualHost *:80 has no VirtualHosts
[ OK ]

One website works perfectly and the other brings me to the root directory for my two websites so in a browser I see two directorys which are my two websites. I checked, double checked and triple checked my files for errors and all paths are correct.

I hope this makes sense to someone.

Thanks!
-Nausser

[ Parent | Reply to this comment ]

Posted by peopleunit (70.249.xx.xx) on Wed 22 Jul 2009 at 23:24
[error] VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results

I had that error for a while also, I removed the port designation... :80

...and the error disappeared.

[ Parent | Reply to this comment ]

Posted by Anonymous (189.144.xx.xx) on Sat 4 Apr 2009 at 06:07
hi i try to set virtual host with out sucess the thing is also i need to make a connection with tomcat6, appearly i doing all rigth but when i put in the browser appears forbiden error 403 and small letters the name of the connector how i know if the connector is working also i try to make a connector but i cant find the apache extension tool another thing i have to set dns for example.com example.net for this works or doesnt matter. i really appreciate the help bye

[ Parent | Reply to this comment ]

Posted by rexuk (189.144.xx.xx) on Wed 8 Apr 2009 at 23:43
hi i found this article very usefull but somebody help me to configure apache2 to work with tomcat6 and postgresql
bye

[ Parent | Reply to this comment ]

Posted by Anonymous (80.192.xx.xx) on Thu 7 May 2009 at 17:44
Guys this guide dosen't work, when I restart apache2 I get; Forcing reload of web server (apache2)...[Thu May 07 17:29:33 2009] [warn] NameVirtualHost www.jibend.co.uk:0 has no VirtualHosts, and if I run the command to create the link it tells me the site dosen't exist.
Does Apache actually work?!

[ Parent | Reply to this comment ]

Posted by Anonymous (67.88.xx.xx) on Thu 14 May 2009 at 19:23
I followed the guide to the key on ubuntu and it worked perfect for me. I did have to login as root to create files in the apache2 directory.

[ Parent | Reply to this comment ]

Posted by Anonymous (125.238.xx.xx) on Mon 18 May 2009 at 04:32
Then you are a moron. You don't have to login as root, just use sudo.

[ Parent | Reply to this comment ]

Posted by Anonymous (99.194.xx.xx) on Tue 2 Jun 2009 at 19:27
PERFECT!!! Helped my buddy setup Virtual Hosting, hosting 4 websites so far using this TuT. Thanks!!!!

[ Parent | Reply to this comment ]

Posted by Anonymous (88.107.xx.xx) on Fri 10 Jul 2009 at 18:55
I was trying to do multiple vhosts but whatever url I used went to the default folder, I had everything setup except virtual.conf. once I had that in, it all worked ! thanks for the tutorial!

[ Parent | Reply to this comment ]

Posted by Anonymous (24.241.xx.xx) on Wed 19 Aug 2009 at 22:17
I still cant figure out how to use multiple pages on one server with apache and havent been able to find any information as to how to do that, im using apache 2.2.x, my site is jiwtech.dynalias.com and i have all of the pages coded but i cant link them to the main page.... someone help me out? send me an email if u have answers (jiwtech@ymail.com)

[ Parent | Reply to this comment ]

Posted by Anonymous (69.140.xx.xx) on Tue 3 Nov 2009 at 21:13
If you're still struggling to host multiple sites:
  1. Make sure your etc/apache2/ports.conf contains these two lines
      NameVirtualHost *:80
      Listen 80
    
    if NOT issue this command: (assuming you're in apache2 folder as shown below) and add those two line
     ruvan@ubuntu:/etc/apache2$ sudo gedit apache2.conf
    
  2. And secondly, add a file containing all your top and sub.domains to /sites-enabled folder as shown below by issuing the following command which should create and empty virtualhost file for our sites named website(.com/.net etc):
     ruvan@ubuntu:/etc/apache2$ sudo touch sites-enabled/website
    
    And add these lines(the minimal version) to the file we just created.
    #Add top domains as many as you need
    <VirtualHost *:80>
          	ServerName  website.com
    	DocumentRoot /home/ruvan/www/website.com
    	DirectoryIndex index.php index.html
    </VirtualHost>
    
    <VirtualHost *:80>
          	ServerName  website.net
    	DocumentRoot /home/ruvan/www/website.net
    	DirectoryIndex index.php index.html
    </VirtualHost>
    
    #And a sub domain for website.com (add as many as you require)
    <VirtualHost *:80>
          	ServerName  my.website.com
    	
    	#set subdomain folder created inside main domain website.com
    	DocumentRoot /home/ruvan/www/website.com/my 
    	
    	DirectoryIndex index.php index.html
    </VirtualHost>
    
    Note: You don't really need separate files for each and every domain. So to keep things simple I added one virtual host file to website.com (but you can ad as many as you need)
  3. Finally, the most imprtant step: you need to do is to map all the site names we just created in the etc/hosts to an IP (127.0.0.1 in this case), or unless you won't be able to access your named sites on the browser.
     127.0.1.1	website.com
     127.0.1.1	my.website.com
     127.0.1.1	website.net
    
Tested to work on Ubuntu9.1-x64 running VMWare Player on XPSP3.

ruvan@http://dealbit.com

[ Parent | Reply to this comment ]

Posted by Anonymous (70.43.xx.xx) on Fri 4 Dec 2009 at 16:22
Can


NameVirtualHost *:80
Listen 80


be


NameVirtualHost xxx.xxx.xxx.xxx:80
Listen 80


I would then assume that my ports.conf file would have to include the same as well as my sites-available file.

Thanks,
cdb

[ Parent | Reply to this comment ]

Posted by Anonymous (93.134.xx.xx) on Mon 26 Jul 2010 at 17:10
I have a question that is probably quite simple for most of the guys here, but it's been bugging the hell out of me for the past 2 days. I have enabled wildcard DNS on my server, and now want to create a redirect such that all subdomains and subdirs of those subdomains get redirected. So if someone puts in

subdomain.example.com/sub/dir

I want them to see the content that I have in this directory:

public_html/~subdomain/sub/dir

Thanks for the help :)

[ Parent | Reply to this comment ]

Posted by aditi (59.95.xx.xx) on Tue 17 Aug 2010 at 14:42
Hi,

I have three different sites with the same IP address using Name Virtual Host. My conf settings in httpd.conf redirects first two sites properly. But for the third Virtual Host block, it always redirects to the first address.

Please let me know if I am missing any settings. I have tried it a lot but www.code3.com always opens up the index page of www.code1.com.

Code:

NameVirtualHost 74.188.20.115

<VirtualHost 74.188.20.115>
DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Code1"
ServerName www.code1.com
DirectoryIndex Index.php
</VirtualHost>

<VirtualHost 74.188.20.115>
DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Code2"
ServerName www.code2.com
ServerAlias code2.com
DirectoryIndex index.php
</VirtualHost>

<VirtualHost 74.188.20.115>
DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Code3"
ServerName www.Code3.com
ServerAlias Code3.com
DirectoryIndex index.php
</VirtualHost>

Any help will be highly appreciated. Thanks

[ Parent | Reply to this comment ]

Posted by Anonymous (180.216.xx.xx) on Thu 19 May 2011 at 16:31
Did you ever get a fix to this?
Mine is the same (with :80 at the end) and it does the same.

Tried everything!

[ Parent | Reply to this comment ]

Posted by Dziamid (77.74.xx.xx) on Sun 29 Aug 2010 at 16:34
Unless I manually add entry '127.0.0.1 mydomainname' to /etc/hosts nothing works. But there's nothing about this file in the tutorial. What I am doing wrong? What does your /etc/hosts file looks like?

[ Parent | Reply to this comment ]

Posted by Anonymous (68.37.xx.xx) on Mon 12 Mar 2012 at 15:23
Yeah, I am having issues with this tutorial too. It only works if I add entries to the /etc/hosts file. Either I am missing something or the author forgot to add info about /etc/hosts or they assumed it was common knowledge.

[ Parent | Reply to this comment ]

Posted by Anonymous (68.37.xx.xx) on Mon 12 Mar 2012 at 16:19
K, I was reading this again and in fairness to the author, they do say this in a non-explicit way.

"The only thing you need is for your domain names to resolve to the IP address of your webserver." <insert sentence about adding a line to /etc/hosts here>

[ Parent | Reply to this comment ]

Posted by Anonymous (86.25.xx.xx) on Sun 14 Nov 2010 at 15:59
So I have follows the guide and still have come a few issues. Bellow is my setup

virtual.conf
#
# We're running multiple virtual hosts.
#
NameVirtualHost *:80

root@demigod:/home/usr# cat /etc/apache2/conf.d/virtual.conf
#
# We're running multiple virtual hosts.
#
NameVirtualHost *:80

root@demigod:/home/usr# cat /etc/apache2/sites-available/www.readmypcap.co.uk
#
# readmypcap.co.uk (/etc/apache2/sites-available/www.readmypcap.co.uk)
#
<VirtualHost *:80>
ServerAdmin webmaster@readmypcap.co.uk
ServerName www.readmypcap.co.uk
ServerAlias readmypcap.co.uk

# Indexes + Directory Root.
DirectoryIndex index.php index.html
DocumentRoot /var/www/www.readmypcap.co.uk/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/www.readmypcap.co.uk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>


# Logfiles
ErrorLog /var/www/www.readmypcap.co.uk/logs/error.log
CustomLog /var/www/www.readmypcap.co.uk/logs/access.log combined
</VirtualHost>

However when I try to browse this virtual domain I keep getting directed to my first default site. Have I over looked anything??

Thanks

[ Parent | Reply to this comment ]

Posted by chris (213.187.xx.xx) on Sun 14 Nov 2010 at 17:42
[ View Weblogs ]
Have you enabled the site (in other words - is the file www.readmypcap.co.uk also available under /etc/apache2/sites-enabled ? If not - you can use a2ensite www.readmypcap.co.uk to enable it.

[ Parent | Reply to this comment ]

Posted by Anonymous (86.25.xx.xx) on Sat 4 Dec 2010 at 13:23
The site had been enabled. I ended up jumping on irc and asking some nice people there. After too many changes to remember I have apache2 and vhosts working as they should but thanks for the advises none the less

[ Parent | Reply to this comment ]

Posted by webminder (94.229.xx.xx) on Fri 11 Feb 2011 at 23:13
That guide in not complete, partially useful, but i lost a lot of time trusting this guide... as is made it doesn't work...i tested it on Debian Squeeze and i doesn't work... in order to let this guide work add:
- /etc/apache2/ports.conf configuration file.
- /etc/hosts file.
- and site-available are not configured correctly, please follow this guide instead:
http://serverfault.com/questions/1405/apache2-startup-warning-nam evirtualhost-80-has-no-virtualhosts

[ Parent | Reply to this comment ]

Posted by Anonymous (207.34.xx.xx) on Sat 7 May 2011 at 01:40
Hi I have another config question scenario for you.
We have an Apache web server in a screened network
The server had 2 NICs in it. One used for Administration Management and the other for the Web traffic


The standard set up includes mulitple sites
1) admin
2) sponsor
3) guest

each of these sites allows differnt access rights.
Unfortunately Apache is running on All NIC interfaces.

I would like to know how I can configure Apache to run
1) Admin on the Management NIC
2) Sponsor on the Management NIC
and
3) Guest on the Web Traffic Nic

Is this possible with a single instance of Apache running, or do I have to run two separate instances on different NICs using the Listen directive

[ Parent | Reply to this comment ]

Posted by Anonymous (121.72.xx.xx) on Wed 1 Jun 2011 at 06:58
Thank you for the step by step. I had looked for a while on how to do this and yours is the clearest, most straight forward and working example I found.

Many thanks.
Shane

[ Parent | Reply to this comment ]

Posted by mitho7 (122.105.xx.xx) on Sun 17 Jul 2011 at 05:37
hello friends,

I'm using Debian GNU/Linux 6.0.2 (squeeze) and Apache 2.2. I have set the virtual hosting as per the example.

My site comes if i type full url (www.example.com/index.html) but if i do not use index.html (www.example.com/) comes up page cannot display. I have default site set up which works ok. if i type the ip address (http://192.168.1.3/) it can read the index.html.

I have dir module loaded. also have set up the DirectoryIndex index.html

under sites-available i have default:

<VirtualHost *>
ServerName no_vhost_entry:80
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html/default

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/default>
Options Indexes FollowSymLinks MultiViews
AllowOverride Limit
Order allow,deny
allow from all
</Directory>
<IfModule mod_headers.c>
Header set Cache-Control no-cache
</IfModule>

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
</VirtualHost>

under sites-available i have www.example.com:

<VirtualHost *>
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/www/www.example.com/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /home/www/www.example.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/www.example.com/logs/error.log
CustomLog /home/www/www.example.com/logs/access.log combined
</VirtualHost>

please need some direction here.

Regards,
Bip

[ Parent | Reply to this comment ]

Posted by mitho7 (122.105.xx.xx) on Sun 17 Jul 2011 at 10:31
i feel so stupid now. it is working file. It's my browser mozilla, i clear the cache and working ok.

[ Parent | Reply to this comment ]

Posted by alkhader (213.132.xx.xx) on Thu 20 Oct 2011 at 12:58
Thank you for this very helpful article.

I have done all the mentioned steps.

I have my own server and a static IP address and I want to show my websites on the browser and I want to access it via IP address? example: xxx.xxx.xxx.xxx/mywebsite/index.php

Kind Regards,

[ Parent | Reply to this comment ]

Posted by Anonymous (79.97.xx.xx) on Tue 29 Nov 2011 at 23:04
Fantastic article, even better are the questions and answers below. A wonderful resourse that is very hard to find elsewhere. The way you put it makes it clear. Thanks.

[ Parent | Reply to this comment ]

Posted by Anonymous (109.232.xx.xx) on Tue 24 Jan 2012 at 05:49
If you added NameVirtualHost *:80 to virtual.conf, delete this string in file ports.conf

[ Parent | Reply to this comment ]

Posted by Anonymous (217.129.xx.xx) on Wed 14 Mar 2012 at 16:56
To all my Anonymous cousins who say this is not working and because I'm a bit pi**ed with some comments like "this guide doesn't work", on behalf of newcomers I'm here to tell

This way of doing multiple virtualhost websites WORKS even as per today (see my post date above).

It's almost P&P if you have the correct domains or virtual domains working well - don't expect having google.com pointing to any site you create; just take the time to read a bit all answers already posted on ways of doing things, then Plug & Pray. If you don't like then just unPlug & Pay other options in the "market" and do not post negative comments.

Thank you Steeve for your time and patience.

LuizCB

[ Parent | Reply to this comment ]

Posted by RTamas (176.63.xx.xx) on Sun 13 May 2012 at 16:37
I did everything correctly that the article mentioned, but I'm having some issues here. First of all when I try to open example.com or www.example.com my browser redirects me to an external webpage.

Any idea what might causing this issue?
Note: Do I have to set anything in /etc/hosts?

[ Parent | Reply to this comment ]

Posted by Anonymous (207.182.xx.xx) on Mon 31 Dec 2012 at 15:13
tnx a milllllliooooooon

[ Parent | Reply to this comment ]

Posted by Anonymous (86.173.xx.xx) on Thu 23 May 2013 at 10:49
Brilliant, many thanks for that.

[ Parent | Reply to this comment ]

Posted by Anonymous (74.215.xx.xx) on Sat 10 Aug 2013 at 02:32

When I go to example.com it shows up all working BUT
When I go to example2.com it shows up the same as example.com when it should be different

[ Parent | Reply to this comment ]

Posted by Agen_Terminator (82.25.xx.xx) on Sat 19 Oct 2013 at 18:30
As obvious as it is, before anyone spends as much time as I did scratching their head and placing/removing NameVirtualHost in loads of files to get it to work, remember you need to setup etc/hosts!

[ Parent | Reply to this comment ]

Posted by Anonymous (212.110.xx.xx) on Fri 4 Apr 2014 at 18:03
I had trouble setting up virtual hosts on Debian. Here are my conf files so you don't have to fix it like I did with brute force!!!
Maybe this will help if you get problems setting this up. Good luck

################################################################# ##################
#Last end of apache2.conf file No changes were made here
################################################################# ##################
.
.
.

# Include of directories ignores editors' and dpkg's backup files,
# see the comments above for details.

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/

################################################################# ##################
#virtual.conf (Notice it is disabled, I changed alot of items and now it all works not changing anything now)
################################################################# ##################

#
# This is the virtual hosts configuration file
#
#NameVirtualHost *


################################################################# ##################
# ports.conf
################################################################# ##################
# ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *
Listen 80

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

################################################################# ##################
#sites-available directory
################################################################# ##################

default www.example.com www.example.net default-ssl


################################################################# ##################
#Default
################################################################# ##################


<VirtualHost *>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

################################################################# ##################
# www.example.com (/etc/apache2/sites-available/www.example.com)
################################################################# ##################

#
# www.example.com (/etc/apache2/sites-available/www.example.com)
#
<VirtualHost *>
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/www/www.example.com/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/www.example.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>

# Logfiles
ErrorLog /var/www/www.example.com/logs/error.log
CustomLog /var/www/www.example.com/logs/access.log combined
</VirtualHost>

################################################################# ##################
# www.example.net (/etc/apache2/sites-available/www.example.net)
################################################################# ##################

#
# www.example.net (/etc/apache2/sites-available/www.example.net)
#
<VirtualHost *>
ServerAdmin webmaster@example.net
ServerName www.example.net
ServerAlias example.net

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/www/www.example.net/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/www.example.net/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>

# Logfiles
ErrorLog /var/www/www.example.net/logs/error.log
CustomLog /var/www/www.example.net/logs/access.log combined
</VirtualHost>

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 153 votes ~ 0 comments )

 

 

Related Links