Apache Configuration

Postinstallation Notes

Conventions

Text you need to replace will be red and underlined.

Commands you run as root will start with a '#'

Commands you run as a normal user will start with a '$'

These conventions are valid only for this presentation.

DNS configs

We need a domain to demonstrate the use of the same server to host another domain.

Edit /etc/namedb/m/yourzonefile and add the following line

somename IN A 1.2.3.4

Change your serial and bump the zonefile by typing

# ndc reload

HTTPD.conf

This is the main (in some cases only) configuration file for the Apache web server. It's well documented, and should be self explanatory. If unsure, consult your apache book.

Format is the same as most UN*X configuration files.. comments are lines that begin with a '#', blank lines or lines with only whitespace (tabs, spaces, etc) are silently ignored.

Consists of different sections denoted with html-like tags e.g

<some section>

Directives for this section

</somesection>

Sample apache directives and what they do

DocumentRoot – this is a directive that tells apache where on the filesystem it should start looking for whatever the user types in the URL after the domain name. It is only valid in the global and <VirtualHost> contexts/sections.
e.g DocumentRoot /usr/local/apache/mywebs/afnog.org

ServerName – the domain name that refers to this host. Used in a lot in generating error messages, and also in deciding which <VirtualHost> is which etc.
e.g ServerName afnog.org

ServerAlias – used much like ServerName, defines other names that may also refer to this host. Multiple aliases posible, separate using comas. All aliases must resolve to this same server.
e.g ServerAlias www.afnog.org, *.afnog.org

Virtual Hosting

It is not really feasible to have a different machine for each different domain that you want to host. Therefore, web servers can host more than one domain on the same machine. Because the same program is pretending to be a horde of domains, this hosting is called “virtual hosting”. You can do this in one of two ways.

Ways to do virtual hosting

IP based virtual hosting.
Use DNS: have a different IN A record for each domain, and add the IP address to the same webserver. This is ok, but most people in Africa can not (yet) afford to have an IP address for each domain

Name based virtual hosting.
Put one ip address in your IN A records for all the domains you want to host. The IP address you put here should be the one of your webserver. Next step is to tell Apache to chose which DocumentRoot to use based on what the user types in the address bar.

NameVirtualHost directive

Change the line ..

#NameVirtualHost *:80

to

NameVirtualHost *:80

(remove the '#')

You need to do this for each port on which you want to do Name based virtual hosting.. i.e since we have also Apache listening to port 443 for the ssl server, we need to also add another line just below this one which says:

NameVirtualHost *:443

Skip this step if you are doing IP based Virtual hosting. (check the Apache book for details on syntax for this command).

Modified <VirtualHost> section
(add this to your httpd.conf file)

<VirtualHost *:80>
ServerAdmin you@somewhere.com
DocumentRoot /usr/local/apache/your.added.domain
ServerName your.added.domain
ErrorLog logs/your.added.domain-error_log
CustomLog logs/your.added.domain-access_log common

</VirtualHost>

(If you are using IP based virtual hosting, then you need to put the IP address for the particular virtual host instead of the '*' ). Also to have a virtual host on your ssl port you need to replace '80' with '443' and do basically the same thing, but certail SSL options need to be turned on.

For any ip address for which you want to do name based virtual hosting, (i.e have more that one <VirtualHost> section for the same IP address, you must have a corresponding NameVirtualHost directive. Note that this directive accepts more than one IP address on the same line.

Filesystem Issues

Make sure that you have the document root and error logs created.... type

# mkdir /usr/local/apache/your.added.domain

# touch /usr/local/apache/logs/your.added.domain-error_log

# touch /usr/local/apache/logs/your.added.domain-access_log

Check your configuration and restart apache

# /usr/local/apache/bin/apachectl configtest

# /usr/local/apache/bin/apachectl stop

# /usr/local/apache/bin/apachectl startssl

Website creation

At this point if you browsed to http://your.added.domain you will be greeted with an error “You do not have permission to access /”

This is because there are no files in your DocumentRoot and you have not enabled directory indexing on it.

Sample index.html

Create a sample file in /usr/local/apache/your.added.domain called index.html with the following text...

<head>
<title> test page</title>

</head>

<body>
hello world<br>
test page

</body>

Conclusion

Different VirtualHosts added in same way

You need to learn scripting to do this automatically or download ready made programs (see below)

Give clients ftp access to their document roots (not covered here because of time constraints) so they can update their pages automatically without asking you to do that for them.
check http://vsftpd.beasts.org/ for an example of a pretty good ftp daemon.

Check http://freshmeat.net/ for sample packages that will automate addition of new hosts to the httpd.conf file. An example picked from there is: http://www.guanotronic.com/~serge/EDF/

Sample ssl <VirtualHost> configuration

2004-05-19T11:31:49