Blog Archive

Apache HTTP Server sample Configuration file - httpd.conf

Configure SSL on iSeries Apache Server

#Load the SSL module program 
LoadModule ibm_ssl_module /QSYS.LIB/QHTTPSVR.LIB/QZSRVSSL.SRVPGM

# Listen on port 443 for your IP address 
Listen 192.168.100.1:443 

#Create virtual host for port 443 and set the proper SSLAppName to which the certificate is associated
<VirtualHost 192.168.100.1:443>            
  SSLEngine On                            
  SSLAppName QIBM_HTTP_SERVER_APPNAME       
  SSLClientAuth None                      
  SetEnv HTTPS_PORT 443         
</VirtualHost>

Apache permanent Redirect

Redirect 301 /foo http://www.mysamplecode.com/foo

OR

Redirect permanent /foo http://www.mysamplecode.com/foo

Apache error document page

Create your custom page such as error404.html and then reference it in the config file as shown below
ErrorDocument 404 http://www.mysamplecode.com/error404.html 

Apache prevent directory listing

Options -Indexes

Apache Maps URLs to filesystem locations

Alias /icons/ /usr/local/apache/icons/

AliasMatch
This directive is equivalent to Alias, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For example, to activate the /icons directory, one might use:
AliasMatch ^/icons(.*) /usr/local/apache/icons$1 

Apache mod rewrite

RewriteRule Pattern Substitution [flags]
RewriteEngine On                      
RewriteCond %{REQUEST_METHOD} ^TRACE  
RewriteRule .* - [F]           
RewriteRule /product/([0-9]+)  /product?item=$1 [NC,PT]

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.

Consider the following rule:

RewriteRule /pages/(.+) /page.php?page=$1 [QSA]

With the [QSA] flag, a request for /pages/123?one=two will be mapped to /page.php?page=123&one=two. Without the [QSA] flag, that same request will be mapped to /page.php?page=123 - that is, the existing query string will be discarded.

Apache Name-based Virtual Host Support

Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames. Name-based virtual hosting also eases the demand for scarce IP addresses. Therefore you should use name-based virtual hosting unless there is a specific reason to choose IP-based virtual hosting. Some reasons why you might consider using IP-based virtual hosting:

  • Some ancient clients are not compatible with name-based virtual hosting. For name-based virtual hosting to work, the client must send the HTTP Host header. This is required by HTTP/1.1, and is implemented by all modern HTTP/1.0 browsers as an extension. If you need to support obsolete clients and still use name-based virtual hosting, a possible technique is discussed at the end of this document.
  • Name-based virtual hosting cannot be used with SSL secure servers because of the nature of the SSL protocol.
  • Some operating systems and network equipment implement bandwidth management techniques that cannot differentiate between hosts unless they are on separate IP addresses.
NameVirtualHost 192.168.1.5:80

<VirtualHost 192.168.1.5:80>        
   ServerName www.mysamplecode.com  
   DocumentRoot /www/as400/htdocs            
   DirectoryIndex as400.html     
</VirtualHost>

<VirtualHost 192.168.1.5:80>           
   ServerName iSeries.blogspot.com    
   DocumentRoot /www/iSeries/htdocs           
   DirectoryIndex iSeries.html           
</VirtualHost>