使用wsgi和Apache的Django EC2部署 [英] Django EC2 deployment with wsgi and Apache

查看:75
本文介绍了使用wsgi和Apache的Django EC2部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EC2上安装了django的微型实例.我还按照以下几个教程安装了mod-wsgi,postgresql等. 最终,我从bitbucket中提取了项目,并在我的EC2上启动了Apache.不幸的是,我唯一拥有的是Apache页面已失效,而且我已经花了整天的时间阅读并试图弄清楚我在做什么错.

I have a micro instance on EC2 with django installed there. I've also installed mod-wsgi, postgresql etc following several tutorials. Finally I pulled my project from bitbucket and started Apache on my EC2. Unfortunately, the only thing I have is defauld Apache page and I've already spent a day and night reading and trying to figure out what am I doing wrong.

my_project位于/home/ubuntu目录中.在它的文件夹中,我有wsgi.py文件:

my_project is in /home/ubuntu dir. In it's folder I have wsgi.py file:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

这是我的.conf文件,存储在/etc/apache2/httpd.conf:

This is my .conf file stored in /etc/apache2/httpd.conf:

Listen 80
NameVirtualHost *:80
WSGIPythonPath /home/ubuntu/my_project/

<VirtualHost *:80>
    DocumentRoot /home/ubuntu/my_project
    ServerName www.ec2-54-***-104-**.us-west-2.compute.amazonaws.com
    ServerAlias ec2-54-***-104-**.us-west-2.compute.amazonaws.com
    ErrorLog /home/ubuntu/my_project/apache/error_log
    CustomLog /home/ubuntu/my_project/access_log_common

    WSGIScriptAlias / /home/ubuntu/my_project/wsgi.py
    Alias /static/ /home/ubuntu/my_project/static/

    <Directory /home/ubuntu/my_project/static>
        Require all granted
    </Directory>

    <Directory /home/ubuntu/my_project>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

</VirtualHost>

当我尝试

/etc/init.d/apache2 stop 

,相反:

python manage.py runserver 0.0.0.0:80

它工作正常,我可以使用IP作为url从浏览器连接到我的应用程序. 它使我了解到setting.py文件很好(是吗?),问题出在wsgi.py或httpd.conf中.

It works fine and I'm able to connect to my app from browser with IP as url. It gives me understanding that setting.py file is fine (am I right?) and problem is or in wsgi.py or in httpd.conf.

当我停止开发服务器并再次启动Apache时,我将获得默认的Apache页面.您能帮我发现我的文件有什么问题吗?

When I stop my development server and start Apache again, I get defauld Apache page. Can you help me please to find whats wrong with my files?

apache的权限:

Permissions for apache:

ubuntu@ip-172-**-**-69:~$ ls -ld my_project/
drwxr-xr-x 10 www-data www-data 4096 May 26 19:51 project/

推荐答案

通常,您不应使用IP地址作为ServerName,它必须是访问该站点的主机名(FQDN).

You normally shouldn't use an IP address for ServerName, it has to be the hostname (FQDN) that the site is accessed as.

您缺少与您对WSGIProcessGroup的使用相对应的WSGIDaemonProcess指令.

You are missing a WSGIDaemonProcess directive to correspond to your use of WSGIProcessGroup.

将DocumentRoot设置为应用程序的源代码是不安全的做法.

It is bad security practice to set DocumentRoot to be where your source code for your application is.

最后,运行Apache的用户通常无法访问用户主目录下的内容.

Finally, stuff under a users home directory is not usually accessible to the user that Apache runs as.

建议返回并再次查看Django网站上的mod_wsgi部署文档以获取开始.

Suggest go back and review the mod_wsgi deployment documentation on the Django site again for a start.

这篇关于使用wsgi和Apache的Django EC2部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆