apache配置文件(省略無關配置):
<VirtualHost *:80>
WSGIDaemonProcess DjangoProject processes=2 threads=15 python-path=/home/andrew/hg_repo/Django
WSGIProcessGroup DjangoProjectAlias /static/js/ /home/andrew/hg_repo/Django/DjangoProject/
static/js/Alias /static/css/ /home/andrew/hg_repo/Django/DjangoProject/
static/css/WSGIScriptAlias / /home/andrew/hg_repo/Django/DjangoProject/wsgi.py#WSGIPythonPath /home/andrew/hg_repo/Django<Directory "/home/andrew/hg_repo/Django/DjangoProject">Order allow,denyAllow from all</Directory></VirtualHost>
這里讓mod_wsgi工作在daemon模式下(官方推薦),python-path表明項目包的路徑。WSGIPythonPath 一項在VirtualHost 內不能使用,只能放到httpd.conf中,作用與python-path相同。
注意 Alias /static/js/及css要放在WSGIScriptAlias前面,讓靜態文件給apache先處理。
另外,如果django的settings.py中把Debug設為了False,必須修改以下配置:
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
改為
ALLOWED_HOSTS = [”*“]
當然,TIME_ZONE的值也應當首先改為'Asia/Shanghai' (沒有北京的)