the lastest Django framework is 1.5.1 while some references are still based on previous distributes.
You could find the newest guideness here: https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/
But you may need some old references since the lastest one can't cover most.
Here is a reference of django 1.2 https://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/
They will teach you how to deploy django application on apache and other engines such as nginx, lightd or etc..
One thing we should notice:
if you are going to deploy a Django1.5.1 app with apache and mod_wsgi, you will need to edit the following files.
1. wsgi.py
You need to edit the file " wsgi.py " from the folder of your application.
import os import sys path = '/var/www/jjlmsite' # 这里为了能让jjlmsite直接被import到,加入到系统路径里面去 if path not in sys.path: sys.path.append(path) # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks # if running multiple sites in the same mod_wsgi process. To fix this, use # mod_wsgi daemon mode with each site in its own daemon process, or use os.environ["DJANGO_SETTINGS_MODULE"] = "jjlmsite.settings" #这里释放注释 # os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jjlmsite.settings") 这里被注释掉 # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. from django.core.wsgi import get_wsgi_application #这里将不做更改 application = get_wsgi_application() # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application)
官方网站上没有上面操作的介绍,所以,在deploy的时候,需要注意一下是否将app的文件夹加入到python的系统路径里面去了。这点比较重要。结合了1.2和1.5的django手册才看到的。
2. httpd.conf
you need to add something like this into httpd.conf
WSGIScriptAlias /gopalace /var/www/jjlmsite/jjlmsite/wsgi.py # url /gopalace will invoke the wsgi.py file # WSGIPythonPath /var/www/jjlmsite # WSGIPythonPath is the main folder path of your django project <Directory /var/www/jjlmsite/jjlmsite> # the folder which has wsgi-functional files <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory>
上面的WSGIPythonPath /var/www/jjlmsite 是告诉Python 哪个文件夹是有可执行的py文件的。
具体效果如下:
响应的是django的app程序返回的结果。
如果想转换端口访问(非一口多用,一口多用比较混乱,apache效率比较小),让单独的端口直接host一个django的app。则一定需要Using mod_wsgi daemon mode
详情请见:https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode
当需要serve静态页面的时候,可以选择nginx等。具体地址如下:
https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/#serving-files