A web server is a combination of computer hardware and software which delivers web pages to remote computers using web browsers. Here, we will focus on web server program which is very famous called Apache web server.
Installation of Web Server :
Before you start installing Apache, use the following command to check if it is already installed -
# rpm -q apache
Configuration of Web Server :
Depending on the version of Apache installed, you might have to edit one or three configuration files. If the Apache is installed by rpm in RedHat, you will need to edit /etc/http/conf. If it is installed from source code, most probably the configuration files will be located at /usr/local/apache/conf. Other location could be /etc/httpd/apache/conf or /etc/apache/conf.
Note: All the files to be served by the web server has to be stored in a predefined directory. It is defined in the configuration file. The top level of the directory is called Document Root.
Note: linuxconf package and comanche provides GUI interface for configuring Apache.
Manually Configuring Text-based Configuration files :
Older version of Apache used to have 3 configuration files as follows -
1. httpd.conf : Web Server daemon configuration
2. access.conf : Access and directory control
3. srm.conf : resource configuration
In the recent version of Apache, all these three files have been combined in one file - httpd.conf to avoid confusion. This file is very well documented.
Tuning the Web Server :
1. Turn-off Hostname Resolving : To turn this off, set the directive HostnameLookups to off in the httpd.conf file.
2. The Server Pool Directives set up : Apache maintains a server pool to answer many simulataneous accesses. Set the following as follows -
3. The Server Status Handler :
You should set this server status handler to view the server status online. You need to uncomment the following section in the Apache Configuration file.
order deny, allow
deny from all
allow from your.ip.address # Change to your actaul IP address
4. Apache Log Files :
Type this command to viwe Apache log files -
# tail -f /var/log/httpd/access_log
ADDING VIRTUAL HOSTS
Imagine if you have to host more than one website, do you need to setup separate web server for each one of them. Virtual hosting solves this problem and you can host multiple web sites on a single machine running Apache web server software.
There are two methods for Virtual hosting in Apache :
1. IP Address based Virtual Hosting
2. Name based Virtual Hosting
IP Address Based Virtual Hosting :
This type of virtual hosting needs a separate IP address for each web site you intend to host on the machine. This can be achieved either by using IP Aliasing or by installing additional network cards and assigning different IP addresses for each site. Also, this method is considered more reliable as it doesn't require any special feature on the browser side.
There are two methods of setting up IP address based Virtual hosting :
1. Multiple Daemons
2. Single Daemons
Multiple Daemons :
This requires to separate installation of Apache for each website and then change the IP address of the Listen directive to the httpd.conf file.
Single Daemons :
This methods requires only one installation of Apache for all web sites and some configuration in httdpd.conf file. The VirtualHost directive is key to set up this. Using this - you can setup different docment root directories, server administrators, log files for each host etc.
For example - to setup two website called www.example1.com and www.example2.com, tyoical configuration will look as follows -
< VirtualHost 192.168.1.1 >
< /VirtualHost >
< VirtualHost 192.168.1.2 >
< /VirtualHost >
Name Based Virtual Hosting
Name based Virtual Hosting is common in use for shared hosting. It doesn't require separate IP address for each website hosted on a machine. Server uses HTTP/1.1 protocol to know which web address a browser is requesting from it.
Setup is similar to very similar to IP address based Virtual hosting setup. The main difference is that you must use the NameVirtualHost directive in the httpd.conf file.
A typical setup example will look like this :
<VirtualHost 192.168.1.2 >
< /VirtualHost >