Apache

Configuration

Configure Apache to set headers with responses

The below is an example of setting a header with text and the other setting the normally used Cache-Control header:

  Header [condition] set test "This is a string."
  Header [condition] set Cache-Control max-age=30

[condition] can be:

There can be several difference actions in the place of set:

The available variables that can be used to return data are:

Virtual Hosts

IP Based

You are able to specify multiple web pages which connect to the one host and separate which page to load based on the private/public IP address that is used. Example, this uses the private IP’s which are associated with a physical or virtual interface:

Listen 80

<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example.org
</VirtualHost>
Server Name Based

You are able to specify multiple web pages which connect to the one host and separate which page to load based on the server name. Example:

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org
</VirtualHost>
Name based for sub-domains

NOTE: This could be used specifying a mixture of options but for simplicity this is same IP and same port.

This requires the Host header being sent to the webserver to determine which content to return, otherwise it will return the default listing. This configuration would allow the URL’s:

to be run on this webserver and return the content for the correct domain. Will require entries for each of the URL above in DNS to be associated with the IP of this webserver.

NameVirtualHost *:80

<VirtualHost *:80>
# primary vhost
DocumentRoot /www/subdomain
RewriteEngine On
RewriteRule ^/.* /www/subdomain/index.html
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/subdomain/sub1
ServerName www.sub1.domain.tld
ServerPath /sub1/
RewriteEngine On
RewriteRule ^(/sub1/.*) /www/subdomain$1
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/subdomain/sub2
ServerName www.sub2.domain.tld
ServerPath /sub2/
RewriteEngine On
RewriteRule ^(/sub2/.*) /www/subdomain$1
</VirtualHost>