Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created January 28, 2011 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacobian/800974 to your computer and use it in GitHub Desktop.
Save jacobian/800974 to your computer and use it in GitHub Desktop.
### Basic daemon config
ServerRoot "/etc/apache2"
PidFile ${APACHE_PID_FILE}
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
ServerTokens ProductOnly
ServerAdmin webmaster@djangoproject.com
### Listen on localhost:8000 (behind the proxy)
Listen localhost:8000
### Worker features
Timeout 30
StartServers 5
MinSpareThreads 5
MaxSpareThreads 10
ThreadLimit 20
ThreadsPerChild 20
MaxClients 100
MaxRequestsPerChild 10000
KeepAlive Off
### Modules
LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so
LoadModule authz_user_module /usr/lib/apache2/modules/mod_authz_user.so
LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so
LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
LoadModule dir_module /usr/lib/apache2/modules/mod_dir.so
LoadModule env_module /usr/lib/apache2/modules/mod_env.so
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
LoadModule status_module /usr/lib/apache2/modules/mod_status.so
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
### Logging
# X-Real-IP gets set by nginx; log that instead of REMOTE_IP
# A possible improvement would be to replace %u with a header set by Django
# to the action Django user.
LogFormat "%{X-Real-IP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined_behind_nginx
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined_behind_nginx
### Default server features
AddDefaultCharset utf-8
DefaultType text/plain
TypesConfig /etc/mime.types
DirectoryIndex index.html
DocumentRoot /var/www
### Directory permissions
<Directory />
Options None
AllowOverride None
Options FollowSymLinks
</Directory>
### Server status
<Location /__status__>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Location>
### App config follows.
NameVirtualHost *
<VirtualHost *>
ServerName djangoproject.com
ServerAlias www.djangoproject.com
ServerAlias ve.djangoproject.com
ServerAlias www.ve.djangoproject.com
ErrorLog /var/log/apache2/www-error.log
CustomLog /var/log/apache2/www-access.log combined_behind_nginx
WSGIScriptAlias / /home/www/djangoproject.com/src/wsgi-scripts/www.wsgi
WSGIDaemonProcess www user=www-data group=www-data processes=2 threads=10 display-name=%{GROUP} maximum-requests=5000
WSGIProcessGroup www
</VirtualHost>
<VirtualHost *>
ServerName docs.djangoproject.com
ServerAlias docs.ve.djangoproject.com
ErrorLog /var/log/apache2/docs-error.log
CustomLog /var/log/apache2/www-access.log combined_behind_nginx
WSGIScriptAlias / /home/www/djangoproject.com/src/wsgi-scripts/docs.wsgi
WSGIDaemonProcess docs user=www-data group=www-data processes=2 threads=10 display-name=%{GROUP} maximum-requests=5000
WSGIProcessGroup docs
</VirtualHost>
<VirtualHost *>
ServerName code.djangoproject.com
ErrorLog /var/log/apache2/code-error.log
CustomLog /var/log/apache2/code-access.log combined_behind_nginx
<Location /login>
AuthName "Django's Trac"
AuthType Basic
AuthBasicProvider wsgi
WSGIAuthUserScript /home/www/djangoproject.com/src/wsgi-scripts/www.wsgi
Require valid-user
</Location>
<Location /svn>
DAV svn
SVNPath /home/svn/django
<LimitExcept GET PROPFIND OPTIONS REPORT>
AuthName "Django SVN repository"
AuthType Basic
AuthBasicProvider wsgi
WSGIAuthUserScript /home/www/djangoproject.com/src/wsgi-scripts/www.wsgi
WSGIAuthGroupScript /home/www/djangoproject.com/src/wsgi-scripts/www.wsgi
Require wsgi-group committers
Require valid-user
</LimitExcept>
</Location>
WSGIScriptAlias / /home/trac/trac.wsgi
WSGIDaemonProcess trac user=www-data group=trac processes=2 threads=10 display-name=%{GROUP} maximum-requests=5000
WSGIProcessGroup trac
</VirtualHost>
import os
import sys
import site
#
# Bootstrap
#
SITE_PACKAGES = '/home/www/djangoproject.com/lib/python2.6/site-packages'
# Remember original sys.path.
prev_sys_path = list(sys.path)
# Add each new site-packages directory.
site.addsitedir(SITE_PACKAGES)
# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
# Bootstrap Django
here = os.path.dirname(__file__)
parent = os.path.dirname(here)
sys.path.append(parent)
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_website.settings.www'
#
# WSGI application
#
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
#
# WSGI auth handlers
#
from django import db
from django.contrib.auth.models import User
def check_password(environ, user, password):
try:
user = User.objects.get(username=user, is_active=True)
if user.check_password(password):
return True
return False
except User.DoesNotExist:
return None
finally:
db.connection.close()
def groups_for_user(environ, user):
try:
u = User.objects.get(username=user)
except User.DoesNotExist:
return []
return [g.name.lower() for g in u.groups.all()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment