我有一个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()
我从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>
在apache2 / sites-enabled下
<VirtualHost *:8080>
ServerName www.mysite.com
ServerAlias mysite.com
<Directory /home/jeffrey/www/ddt/apache/>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
ErrorLog /home/jeffrey/www/ddt/logs/apache_error.log
CustomLog /home/jeffrey/www/ddt/logs/apache_access.log combined
WSGIDaemonProcess datadriventrading.com user=www-data group=www-data threads=25
WSGIProcessGroup datadriventrading.com
WSGIScriptAlias / /home/jeffrey/www/ddt/apache/ddt.wsgi
</VirtualHost>
如果我是正确的,则上面的这3个文件应该正确地允许我的django应用程序在端口8080上运行。
我有以下nginx / proxy.conf文件
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
在启用nginx /站点的情况下
server {
listen 80;
server_name www.mysite.com mysite.com;
access_log /home/jeffrey/www/ddt/logs/nginx_access.log;
error_log /home/jeffrey/www/ddt/logs/nginx_error.log;
location / {
proxy_pass http://127.0.0.1:8080;
include /etc/nginx/proxy.conf;
}
location /media/ {
root /home/jeffrey/www/ddt/;
}
}
如果我是正确的话,这两个文件应将nginx设置为在HTTP端口80上接收请求,然后将请求定向到在端口8080上运行django应用程序的apache。如果我转到mysite.com,我看到的只是欢迎使用Nginx !
任何有关如何调试此建议?