Services     Software     Commentary     Design     Astral Musings   
Configuration tips





For almost all environments except Microsoft Windows, Apache is the to go to service for serving web pages.  Alternatives include IIS and ngnix, but unless you have very special hosting requirements, knowing how to setup and maintain web hosting with Apache will cover all but the most demanding web server needs..

Typically Apache is run as the httpd service
Typically configuration files are at ...
Default file serving directory is ...

Fancy Indexing, customizing directory file listings [ edit ]

# cat .htaccess
  Options +Indexes

  <IfModule mod_autoindex.c>
      IndexOptions FancyIndexing NameWidth=*
      AddDescription "GZIP tar archive" .tgz .tar.gz
      AddDescription "RedHat Package" .rpm
      AddDescription "Debian Package" .deb
      IndexIgnore RCS CVS *,v *,t .DS_Store *.log
      IndexIgnore .??* RCS CVS *,v *,t .DS_Store

Error page instead of Index Page for root folders

In some versions of Linux, Apache is preconfigured to disable Indexes for the root folder. Often the directive in NOT in httpd.conf but in welcome.conf
# pwd

# diff conf.d/welcome.conf
  < <LocationMatch "^/+$">
  <     Options -Indexes
  <     ErrorDocument 403 /error/noindex.html
  < </LocationMatch>
  > #<LocationMatch "^/+$">
  > #    Options -Indexes
  > #    ErrorDocument 403 /error/noindex.html
  > #</LocationMatch>

2 GByte file limitation

Apache does not handle serving files larger than 2 GBytes. If Options Indexes is enabled, large files will simply not show in the list.
Allegedly an upcoming release may soon support large files. But wait! Should it? Apache is suited well for serving web pages. Web pages typically are comprised of small files to allow quick download and viewing. Files larger than a GByte should use something other than Apache as means of distribution. Web browsers also do not handle large file downloads well (file size > 2 GBytes). Transfering large files is really the domain of low-level operating system functions. Modern operating systems allow mounting remote volumes and interacting with very large files at the file system level.
  • NFS works well for non-windows systems
  • SMB (Samba) works well for Windows systems
  • other?

Preventing unresolved ServerName at startup

May need tweak httpd.conf so that ServerName is set before starting apache.  Also check that /etc/sysconfig/network is correct.

# /etc/rc.d/init.d/httpd restart


# cat /etc/sysconfig/network


CGI errors only for some script files

Make sure that line ending are legitimate for host OS (e.g. UNIX/Linux expects just a LF). If the #!/... line doesn't have the correct line ending inexplicably wonky errors like the following will show up in apache error logs ...
# tail -f /var/log/httpd/error_log 

  [...] [error] [client] (2)No such file or directory: exec of '/var/www/cgi-bin/' failed
  [...] [error] [client] Premature end of script headers:

Enabling CGI

Apache 2.0.X (now the default with RH 8.0) may not have cgi enabled by default. To test ...
.../httpd.conf tweaks to enable default directory
<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all

# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
Restricting Access - denying requests based on origin
Limit page access to local 192.168.*.* network ...
<Directory "/var/www/html/phpMyAdmin/">
#    AllowOverride None
#    Options ExecCGI Indexes
     Order allow,deny
     Allow from 192.168
#    AddHandler cgi-script .pl
#    AddHandler cgi-script .cgi

Secure Serving - enabling https support

Typically Apache standard install (e.g. RedHat CD) is already set up for this. However, the mod_ssl RPM must also be present for Apache to properly handle https requests (typically using port 443). Classic symptom of this is connection failed messages. Note - unless additional certificate setup is performed, secure pages will generate a unknown certificate a warning prompt with most web browsers.
# yum list \*mod_ssl\*

  Available Packages
  mod_ssl.i386             1:2.0.52-38.ent.centos update

# rpm -qa > now; diff rpm.txt now

  < httpd-suexec-2.0.52-32.ent.centos4
  > httpd-suexec-2.0.52-38.ent.centos4.2
  > mod_ssl-2.0.52-38.ent.centos4.2
  < httpd-2.0.52-32.ent.centos4
  > distcache-1.4.5-6
  > httpd-2.0.52-38.ent.centos4.2

# chkconfig --list > now; diff chkconfig.txt now

  > dc_server     0:off   1:off   2:off   3:off   4:off   5:off   6:off
  > dc_client     0:off   1:off   2:off   3:off   4:off   5:off   6:off

# pwd


# rcsdiff ssl.conf
  < <VirtualHost _default_:443>
  > <VirtualHost *:443>
  >     # this is also default if domain is not matched below
  >     ServerName
  >     DocumentRoot /public/mcd
  > # Ok, SSL needs different IP address/domain, unlike standard port 80 hosted sites.
  > # Secondly, likely the IP address in the certificate must be the actual
  > # public world routable IP address, so using NAT addressed virtual SSL
  > # host will probably cause a certificate warning.
The Art of Secure Key Registration
# cd /etc/httpd/conf/ssl.scr
# openssl  req -new -nodes -keyout private.key -out public.csr
  Santa Clara
  IT Staff

# openssl rsa -in private.key -des3 -out private_hash.key
# rm private.key
# cat public.csr
  Submit key to a key registrat like Verisign.
  Await their email with the contents to use when creating a public_20030821.crt file

# vi public.crt_20030821   extended name reminds us when this certificate expires
# vi .../httpd.conf
  edit SSLCertificateFile
  edit SSLCertificateKeyFile
# service httpd restart
Stay tuned for details about how to setup a custom Certificate Authority server.

Apache - Virtual Hosting
This particularly powerful configuration of Apache allows a single system to act like several completely seperate web servers. This is a very economical solution for ISP's to provide hosting for multiple customers with a single machine. The setup of this is a bit tricky.

Apache - ProxyPass and other fun

Recent versions of Apache offer a built in pass through feature. This pass through feature can be configured to trap certin URL's and spawn requests to other serivices (e.g. ftp, http, ssh, ...) and then feed the response to the second request back to the original requestor. This is quite handy to allow Tomcat service (typically lives on port 8080) to be invoked when a certain request is made to httpd (typically lives on port 80).

Typically ProxyPass adjustments are the only proxy directives that need to be altered for most situations - ALL other proxy directives should remain off.
# diff -r1.1 httpd.conf

< #LoadModule proxy_module       modules/
> LoadModule proxy_module       modules/

< #AddModule mod_proxy.c
> AddModule mod_proxy.c

< #<IfModule mod_proxy.c>
< #ProxyRequests On
> <IfModule mod_proxy.c>
> # Other proxy directives seem to work fine when ProxyRequests Off.
> # Indeed, the only reason to enable ProxyRequests is to provide
> # an open Proxy to the public.  Once an open proxy is discovered
> # by others, it will inevidably be followed by a storm of requests
> # that will waste bandwidth.  Bandwidth loss typically becomes
> # severe enough to affect responsiveness of services on the open
> # proxy server.  Therefore, if ProxyRequests in enabled, it is
> # best to limit its use to a known and trusted network.
> ProxyRequests Off
> # .../devpanther/ <-
> ProxyPass  /devpanther/
> # .../kt/ <-
> ProxyPass  /kt/
> # .../public/ <-
> ProxyPass  /public/

< #</IfModule>
> </IfModule>


Apache - Test an http server using just telnet!

$ telnet 80

  GET / HTTP/1.1
  [ blank return ]


Apache - Legacy
Linux versions before RedHat Linux 7.3 used slightly different configuration conventions. For the most part little has changed and older information may still be handy when maintaining a legacy system.

The default directory Apache serves web pages from is ...

You may want to peruse the configuration files ...
/etc/httpd/conf/srm.conf     (has most of the neeto bits)
zap technologies
tablet | printable