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:~#
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 ]
And you can just reload the server instead of restarting it if you change the config.
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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..
[ Parent | Reply to this comment ]
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 ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
<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 ]
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/ VirtualHostOn 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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
It makes me wonder why it's not setup by the debian installer of apache2.
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
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 ]
[ Send Message | 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... :)
[ Parent | Reply to this comment ]
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 ]
[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 ]
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 ]
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 ]
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 ]
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 ]
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
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 ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
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 ]
[ Send Message | 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.
[ Parent | Reply to this comment ]
"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 ]
thanks
mjh
[ Parent | Reply to this comment ]
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 ]
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 ]
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 ]
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 ]
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 ]
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 ]
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 ]
I had that error for a while also, I removed the port designation... :80
...and the error disappeared.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
bye
[ Parent | Reply to this comment ]
Does Apache actually work?!
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
- 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 lineruvan@ubuntu:/etc/apache2$ sudo gedit apache2.conf
- 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) - 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
ruvan@http://dealbit.com
[ Parent | Reply to this comment ]
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 ]
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 ]
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 ]
[ Parent | Reply to this comment ]