After upgrading one of my private servers a little while ago I decided to expand upon the web-server that was being happily hosted on it for the last year or so. As I cannot find any sample configuration files online that do something similar to what this server does I present to you the configuration files that I used on my server. Hopefully they will be of use to somebody.
As most of the magic is done with virtual hosts the global Apache 2 settings were all left at default values with the exception of “NameVirtualHost” that was set to “*” to enable named-based virtual hosts for all connections.
It may be worth noting that the server runs Ubuntu Linux 6.10 Edgy where the Apache server program itself along with all required modules were installed using APT. As an added bonus of this all virtual hosts are stored in separate files by default for ease of use (Which I highly recommend as well), however nothing is stopping you from placing them all in a single file for your server. It’s your choice.
Set the default virtual host to display one of two sites depending on whether it was accessed from an internal or external host.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <VirtualHost *>
ServerName www.example.com
ServerAlias www.private.lan
ServerAdmin admin@example.com
DocumentRoot /var/www/default
<Directory /var/www/default>
AllowOverride All
Order Allow,Deny
Allow From All
RewriteEngine On
RewriteRule ^(public|private)/ - [L]
RewriteCond %{REMOTE_ADDR} ^192\.168\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.
RewriteRule ^(.*)$ private/$1 [L]
RewriteRule ^(.*)$ public/$1 [L]
</Directory>
<Directory /var/www/default/private>
AllowOverride All
Order Deny,Allow
Deny From All
Allow From 127.0.0.1 192.168 10
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
|
Create a Subversion repository that is accessible from the “svn” subdomain were the project is defined by the first directory (E.g. http://svn.example.com/project1 ) and use an AuthZ permission system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <VirtualHost *>
ServerName svn.example.com
ServerAlias svn.private.lan
ServerAdmin admin@example.com
DocumentRoot /var/www/svn
<Location /project1>
DAV svn
SVNPath /var/svn/project1
AuthType Basic
AuthName "Project 1"
AuthUserFile /home/svn/permissions.passwd
AuthzSVNAccessFile /home/svn/permissions.authz
Require valid-user
</Location>
ErrorLog /var/log/apache2/error.svn.log
CustomLog /var/log/apache2/access.svn.log combined
</VirtualHost>
|
Create a subdomain dedicated to the Trac project management system called “trac” that uses the same directory structure and users as the Subversion.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <VirtualHost *>
ServerName trac.example.com
ServerAlias trac.private.lan
ServerAdmin admin@example.com
DocumentRoot /var/trac
<Location /project1>
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /var/trac/project1
PythonOption TracUriRoot /project1/
AuthType Basic
AuthName "Project 1 Trac"
AuthUserFile /home/svn/permissions.passwd
Require valid-user
</Location>
ErrorLog /var/log/apache2/error.trac.log
CustomLog /var/log/apache2/access.trac.log combined
</VirtualHost>
|
Proxy the contents of an separate server on the local area network that also has a hostname of “dev.example.com” that is defined on a local DNS server (As the other server will get an incorrect “HTTP_HOST” value if the hostnames are different) off the “dev” subdomain.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <VirtualHost *>
ServerName dev.example.com
ServerAlias dev.private.lan
ServerAdmin admin@example.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass / http://dev.example.com/
ProxyPassReverse / http://dev.example.com/
ErrorLog /var/log/apache2/error.dev.log
CustomLog /var/log/apache2/access.dev.log combined
</VirtualHost>
|
Comments
Have your say