n this concluding part of our three-part series on Apache Web server, we look at the remaining directives of main server configuration and understand virtual hosting.
Customizable error response
Customizable error response, the Apache style, comes in three flavors:
1) Plain text
ErrorDocument 500 "The server made a boo boo.
Note: The (") marks it as text, it does not get output.
2) Local redirects
ErrorDocument 404 /missing.html to redirect to local URL /missing.html
ErrorDocument 404 /cgi-bin/missing_handler.pl
Note: You can redirect to a script or a document using server-side-includes.
3) External redirects
ErrorDocument 402 some.other_server.com/subscription_info
Note: Many of the environment variables associated with the original request will not be available to such a script.
The following directives modify normal HTTP response behavior.
The first directive disables keepalive for Netscape 2.x and browsers that spoof it. There are known problems with these browser implementations. The second directive is for Microsoft Internet Explorer 4.0b2, which has a broken HTTP/1.1 implementation and does not properly support `keepalive' when it is used on 301 or 302 (redirect) responses.
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4.0b2;" nokeepalive downgrade-1.0 force-response-1.0
The following directive disables HTTP/1.1 responses to browsers, which are in violation of the HTTP/1.0 spec by not being able to grok a basic 1.1 response.
BrowserMatch "RealPlayer 4.0" force-response-1.0
BrowserMatch "Java/1.0" force-response-1.0
BrowserMatch "JDK/1.0" force-response-1.0
If the perl module is installed, this will be enabled.
Alias /perl/ /home/httpd/perl/
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
Allow http put (such as Netscape Gold's publish feature)
Use htpasswd to generate /etc/httpd/conf/passwd
You must unremark these two lines at the top of this file as well:
LoadModule put_module modules/mod_put.so
AddModule mod_put.c
Alias /upload /tmp
EnablePut On
AuthType Basic
AuthName Temporary
AuthUserFile /etc/httpd/conf/passwd
EnableDelete Off
umask 007
require valid-user
To allow server status reports, use servername/server-status and change the ".your_domain.com" to match your domain to enable.
SetHandler server-status
Order deny,allow
Deny from all
Allow from .your_domain.com
To allow remote server configuration reports go to servername/server-info (requires that mod_info.c be loaded), and now change the ".your_domain.com" to match your domain to enable.
SetHandler server-info
Order deny,allow
Deny from all
Allow from .your_domain.com
You can allow access to local system documentation from localhost by:
Alias /doc/ /usr/doc/
order deny,allow
deny from all
allow from localhost
Options Indexes FollowSymLinks
Checking attacks
There have been reports of people trying to abuse an old bug from pre-1.1 days. This bug involved a CGI script distributed as a part of Apache. By uncommenting these lines you can redirect these attacks to a logging script on phf.Apache.org. Or, you can record them yourself, using the script support/phf_abuse_log.cgi.
Deny from all
ErrorDocument 403 < href="http://phf.Apache.org/phf_abuse_log.cgi"> Apache.org/phf_abuse_log.cgi
Proxy Server directives
Uncomment the following lines to enable the proxy server
ProxyRequests On
Order deny,allow
Deny from all
Allow froms .your_domain.com
Enable/disable the handling of HTTP/1.1 "Via:" headers.
( "Full" adds the server version; "Block" removes all outgoing Via: headers)
Set to one of: Off | On | Full | Block
ProxyVia On
To enable the cache as well, edit and uncomment the following lines:
(no cacheing without CacheRoot)
CacheRoot "/var/cache/httpd"
CacheSize 5
CacheGcInterval 4
CacheMaxExpire 24
CacheLastModifiedFactor 0.1
CacheDefaultExpire 1
NoCache a_domain.com another_domain.edu joes.garage_sale.com
Section 3: Virtual hosts
VirtualHost: If you want to maintain multiple domains/hostnames on your machine you can setup VirtualHost containers for them. Please see the documentation here for further details before you try to setup virtual hosts. You may use the command line option '-S' to verify your virtual host configuration.
If you want to use name-based virtual hosts, you need to define at least one IP address (and port number) for them.
NameVirtualHost 12.34.56.78:80
NameVirtualHost 12.34.56.78
NameVirtualHost 192.192.192.1
VirtualHost example
Almost any Apache directive may go into a VirtualHost container.
ServerAdmin webmaster@host.some_domain.com
DocumentRoot /www/docs/host.some_domain.com
ServerName host.some_domain.com
ErrorLog logs/host.some_domain.com-error_log
CustomLog logs/host.some_domain.com-access_log common
ServerAdmin amby@goldie.com
DocumentRoot /docfile
ServerName www.goldie.com
ErrorLog logs/err
ServerAdmin amby@failure.com
DocumentRoot /htdoc
ServerName www.failure.com
ErrorLog /home/err
ServerName www.chiku.com
DocumentRoot /home/chinu/public_html
ServerName www.chik.com
DocumentRoot /home/
ServerName www.chik.com
DocumentRoot /home/
After editing /etc/httpd/conf/httpd/conf properly, start /etc/rc.d/init.d/httpd restart.
Explanation of this file
1) note means comment (if removed then it means active state)
The main macro, which should be taken in to account for activation, are:
Documentroot
Serverroot
Servername
User_dir
Access_log
Error_log
Server-alias
Script-alias
Now before we go on to explanations lets take an example to host it both, without password protection and with password protection. Lets design an html page and then communicate with the server. After this we will figure out where to put the html and the server programme, which communicates with html in all the three cases.
Normal Hosting
Lets say our machine ip is: 192.192.192.1 and the machine name is kshounish1.linux.com. And these entries are there in /etc/hosts file:
cd /home/httpd/html
vi index.html
then write