Skip to content

Instantly share code, notes, and snippets.

@treffynnon
Created October 3, 2010 21:06
Show Gist options
  • Save treffynnon/608936 to your computer and use it in GitHub Desktop.
Save treffynnon/608936 to your computer and use it in GitHub Desktop.
An Excellent Development Server for a Team of Developers
# This file is /etc/apache2/httpd.conf
# This file is automatically included by Ubuntu in /etc/apache2/apache2.conf
Include /etc/apache2/dev-server.conf
# This file is /etc/apache2/dev-server.conf
# This file is included by /etc/apache2/httpd.conf
# Hide server information and setup VirtualHost container skeletons for HTTP and HTTPS
# Hide server vitals from responses
ServerSignature Off
ServerTokens Min
# Mass Virtual Hosting
<VirtualHost *:80>
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
Include /etc/apache2/dev-server-vhost.conf
</VirtualHost>
# SSL Mass Virtual Hosting
<VirtualHost *:443>
<IfModule mod_ssl.c>
SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
</IfModule>
Include /etc/apache2/dev-server-vhost.conf
</VirtualHost>
# This file is /etc/apache2/dev-server-vhost.conf
# This file is included from the virtual hosts in /etc/apache2/conf.d/dev-server.conf
# The guts of the VirtualHost container with robot blocking and mass virtual hosting via mod_rewrite
ServerName dev.example.org
ServerAdmin [email protected]
ServerAlias *.dev *.dev.example.org staging.example.org *.staging *.staging.example.org proof.example.org *.proof *.proof.example.org
DocumentRoot /var/www
LimitInternalRecursion 15
# Detect bots by user agent
SetEnvIfNoCase User-Agent ".*(Googlebot|msnbot|Yahoo! Slurp|YahooSeeker|Yahoo-Blogs|bot|robot|spider|Ask Jeeves|ArchitextSpider|Scooter|AltaVista|Slurp|Crawler|WebCrawler|Lycos).*" bad_bot
# Detect incorrect website access by referer. This is to stop anybody
# clicking on a link from the following search engine's listings.
SetEnvIfNoCase Referer ".*(Google\.|Yahoo\.|Bing\.|Ask\.|Excite\.|Lycos\.|AltaVista\.|WebCrawler\.).*" bad_bot
<Directory /home/>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
Allow from all
Deny from env=bad_bot
</Directory>
<Directory /var/vhosts/virtual>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
Allow from all
Deny from env=bad_bot
</Directory>
<Directory /var/vhosts/proof>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
Allow from all
Deny from env=bad_bot
</Directory>
RewriteEngine on
# Rewrite log settings
RewriteLog /var/log/apache2/dev-rewrite.log
#0-9: 0 = none 9 = verbose
RewriteLogLevel 0
# Block robots with a central robots.txt for all sites
RewriteRule ^/robots.txt$ /var/vhosts/robots.txt [L]
# Filter to parse URLs to lowercase
RewriteMap lowercase int:tolower
# Dev sites
# With the format "user /home/dir/"
RewriteMap vhost txt:/etc/apache2/dev-server-rewrite.map
RewriteCond ${lowercase:%{SERVER_NAME}} ([^.]+)\.([^.]+)\.dev\.
# Windows:
# RewriteCond %1.${vhost:%2}£%2 ^([a-z]+)\.([d].*)£([a-z]+)$
# Linux:
RewriteCond %1.${vhost:%2}£%2 ^([a-z]+)\.(/.*)£([a-z]+)$
# The £%2 is only there so that the developer
# username can be passed between RewriteConds.
# The £ symbol is just a delimiter.
RewriteRule ^/(.*)$ %2/%1/pub/$1 [L,E=VIRTUAL_DOCUMENT_ROOT:%2/%1/pub,E=WE_ARE_ON_STAGING:TRUE,E=DEVELOPER_USERNAME:%3]
# Staging sites
RewriteCond ${lowercase:%{SERVER_NAME}} ([^.]+)\.staging\.
RewriteRule ^/(.*)$ /var/vhosts/staging/%1/pub/$1 [L,E=VIRTUAL_DOCUMENT_ROOT:/var/vhosts/staging/%1/pub,E=WE_ARE_ON_STAGING:TRUE]
# Proof sites
RewriteCond ${lowercase:%{SERVER_NAME}} ([^.]+)\.proof\.
RewriteRule ^/(.*)$ /var/vhosts/proof/%1/pub/$1 [L,E=VIRTUAL_DOCUMENT_ROOT:/var/vhosts/proof/%1/pub,E=WE_ARE_ON_STAGING:TRUE]
# Logging
LogLevel debug
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /var/log/apache2/dev-access.log vcommon
ErrorLog /var/log/apache2/dev-error.log
# This file is /etc/apache2/dev-server-rewrite.map
# This file is included from the virtual hosts in /etc/apache2/dev-server-vhost.conf
# Maps a username to a location in the file system uses the following format:
# name<tab>/dir/location
simon /home/simon/www
joe /home/joe/www
jane /home/jane/www
<?php
// This file is /etc/php/auto_prepend.php
// It is actioned by setting auto_prepend_file="/etc/php/auto_prepend.php" in your PHP INI/Config
// Converts the virtual document root to be the standard document root
if(isset($_SERVER['VIRTUAL_DOCUMENT_ROOT']) and
!empty($_SERVER['VIRTUAL_DOCUMENT_ROOT'])) {
$_SERVER['DOCUMENT_ROOT'] = $_SERVER['VIRTUAL_DOCUMENT_ROOT'];
}
# This file is /var/vhosts/robots.txt
# The central robots.txt file.
User-agent: *
Disallow: /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment