简体   繁体   English

如何使用Django设置Apache

[英]How to setup the Apache with Django

I'm trying to setup Django with apache on an AWS EC2 instance. 我正在尝试在AWS EC2实例上使用apache设置Django。

This is 000-default.conf under /etc/apache2/sites-available looks like this 这是/ etc / apache2 / sites-available下的000-default.conf,看起来像这样

<VirtualHost *:80>
ServerName  mysite
ServerAlias mysite.com
ServerAdmin mysite@gmail.com

DocumentRoot /var/www/mysite
WSGIScriptAlias /mysite /var/www/mysite/mysite/wsgi.py

ErrorLog /home/ubuntu/apache/errors/error.log
CustomLog /home/ubuntu/apache/errors/custom.log combined

</VirtualHost>

My Django project is under /var/www/ My python location /home/ubuntu/anaconda3/bin/python 我的Django项目位于/var/www/我的python位置/home/ubuntu/anaconda3/bin/python

When I access the site this is what I get. 当我访问该网站时,这就是我得到的。

在此处输入图片说明

In the image that you shared, it shows a directory listing as you have no index file set for the root of your virtual server. 在您共享的映像中,由于没有为虚拟服务器的根设置索引文件,因此它显示了目录列表。 You probably don't want your data files exposed to the world . 您可能不希望数据文件公开

To display your Django project when requesting the mysite.com root, consider setting up WSCGI using the WSGIDaemonProcess directive. 要在请求mysite.com根目录时显示Django项目,请考虑使用WSGIDaemonProcess指令设置WSCGI。 You'll probably want to set up some additional directories for static resources, too. 您可能还需要为静态资源设置一些其他目录。 Some simple directory permissions in your VirtualHost configuration and access permissions for your project data files should help get things running safely and reliably. VirtualHost配置中的一些简单目录权限以及项目数据文件的访问权限应有助于使事情安全可靠地运行。

Check out this HOWTO for setting up Apache to serve up Django written by someone awesome at DigitalOcean (skip down to the Configuring Apache section). 查看此HOWTO,以设置Apache来服务 DigitalOcean出色的人编写的Django (跳至“配置Apache”部分)。 Though the documentation I provided is not geared specifically to amazon-ec2, the Apache section should be enough to get you running. 尽管我提供的文档并非专门针对amazon-ec2,但Apache部分应足以使您运行。 Please let me know how it works out. 请让我知道它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM