Posted by Steve on Thu 30 Sep 2004 at 18:50
Apache is probably the most popular webserver for the Linux platform, and despite being very powerful and extensible it is very well documented. In spite of this documentation many people seem to struggle with hosting multiple sites with Apache.
There are two ways to host multiple sites with one Apache instance, and both are very simple to setup. You have the choice of using Name based virtual hosts, or IP based virtual hosts.
In most common situations you will use Name based virtual hosts, this only requires that all the sites you wish to host point to the IP address of your Apache server.
To start with you'll need to install the apache server itself. On a Debian system you will install software via the apt-get system, so as root you need to run the following commands apt-get update and apt-get install apache.
Once this has been done you will find you have Apache installed, and it's default configuration is included inside the directory /etc/apache, by default this will be setup to serve the files that are contained in the directory /var/www.
To enable multiple host support you must add, or uncomment, the following line:
NameVirtualHost *
This sets up Apache to accept the hosts.
Once this is done you need to create the directories to contain your sites, personally I use /home/www/name.of.site.org.
Assuming that you wish to host two sites you should create two directories:
root@skx:# mkdir -p /home/www/www.foo.com root@skx:# mkdir -p /home/www/www.foo.com/htdocs root@skx:# mkdir -p /home/www/www.foo.com/logs root@skx:# mkdir -p /home/www/www.foo.com/cgi-bin root@skx:# mkdir -p /home/www/www.bar.com/ root@skx:# mkdir -p /home/www/www.bar.com/htdocs root@skx:# mkdir -p /home/www/www.bar.com/logs root@skx:# mkdir -p /home/www/www.bar.com/cgi-bin
This gives you the directories to place your content inside htdocs, a directory for the CGI scripts, if you need them, and a directory to contain the logfiles for that host.
The next step is to add the configuration for each site, this can be done by adding the following settings to the default configuration file, /etc/apache/httpd.conf:
<VirtualHost *>
# Basic setup
ServerAdmin webmaster@foo.com
ServerName www.foo.com
DocumentRoot /home/www/www.foo.com/htdocs/
# HTML documents, with indexing.
<Directory />
Options +Includes
</Directory>
# CGI Handling
ScriptAlias /cgi-bin/ /home/www/www.foo.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/www.foo.com/logs/error.log
CustomLog /home/www/www.foo.com/logs/access.log combined
</VirtualHost>
<VirtualHost *>
# Basic setup
ServerAdmin webmaster@bar.com
ServerName www.bar.com
DocumentRoot /home/www/www.bar.com/htdocs/
# HTML documents, with indexing.
<Directory />
Options +Includes
</Directory>
# CGI Handling
ScriptAlias /cgi-bin/ /home/www/www.bar.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/www.bar.com/logs/error.log
CustomLog /home/www/www.bar.com/logs/access.log combined
</VirtualHost>
This sets up two sites, which have their docements and logfiles contained beneath /home/www/www.nameofsite.com. You can adjust the paths if you wish to keep the files elsewhere.
Before attempting to restart the server you should run a quick test to make sure that the configuration file /etc/apache/httpd.conf doesn't contain any errors. To do that you can run:
root@skx:/etc/apache# apachectl configtest Syntax OK root@skx:/etc/apache#
Any errors should be highlighted, but in this case we see that our syntax is OK, so we can restart apache with:
root@skx:/etc/apache# /etc/init.d/apache reload Reloading apache configuration. root@skx:/etc/apache#
[ Parent ]
[ Parent ]
[ Parent ]
I think it should do that anyway - But you could use Apache's notion of a default vhost if not.
The apache docs cover it..
Steve
-- Steve.org.uk
[ Parent ]
If you didn't already find it here's an example.
Steve
-- Steve.org.uk
[ Parent ]
[ Parent ]
[ Parent ]
No different than non-SSL.
Although there's the limitation of using only one unique certificate perl IP address ...
Steve
-- Steve.org.uk
[ Parent ]
[ Parent ]
ScriptAlias is defined in the mod_alias module.
For Apache 1.3.x add the following to your /etc/apache/httpd.conf file:
LoadModule cgi_module /usr/lib/apache/1.3/mod_cgi.so LoadModule alias_module /usr/lib/apache/1.3/mod_alias.so
Or just comment out the line included in the error message if you don't wish to use CGI scripts!
Steve
-- Steve.org.uk
[ Parent ]
[ Parent ]
True there are some modules which allow you to do this without restarting/reloading your Apache setup.
However the package you mention libapache-mod-dynvhost doesn't actually appear to be contained in any of the Debian releases; stable, unstable, or testing.
The main advantage of doing things the way they are presented here, instead of using a mass-virtual-hosting module, is that you can customize each site. For example setting up site-specific Aliases, or enabling/disabling PHP on a site-by-site basis. None of those things are possible in most of the virtual hosting modules.
If you're adding hosts sufficiently often that reloading Apache causes problems then you're probably better off using another approach, such as mod_vhost, or similar.
Steve
--
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
Very good !!
[ Parent ]