我有一个可以使用标准开发环境在本地运行的 django 应用程序。我现在想将其移至 EC2 进行生产。django 文档建议使用 apache 和 mod_wsgi 运行,并使用 nginx 加载静态文件。
我在 Ec2 机器上运行 Ubuntu 12.04。我的 Django 应用程序“ddt”包含一个带有 ddt.wsgi 的子目录“apache”
import os, sys
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/usr/lib/python2.7/site-packages/django/')
sys.path.append('/home/jeffrey/www/ddt/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ddt.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)
我从 apt 安装了 mod_wsgi。我的 apache/httpd.conf 包含
NameVirtualHost *:8080
WSGIScriptAlias / /home/jeffrey/www/ddt/apache/ddt.wsgi
WSGIPythonPath /home/jeffrey/www/ddt
<Directory /home/jeffrey/www/ddt/apache/>
<Files ddt.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>
Run Code Online (Sandbox Code Playgroud)
在 apache2/sites-enabled 下
<VirtualHost *:8080>
ServerName www.mysite.com
ServerAlias mysite.com
<Directory /home/jeffrey/www/ddt/apache/>
Order deny,allow …Run Code Online (Sandbox Code Playgroud)