首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >亚马逊EC2 Django静态文件配置

亚马逊EC2 Django静态文件配置
EN

Stack Overflow用户
提问于 2014-08-18 17:31:54
回答 1查看 1K关注 0票数 1

昨天配置了亚马逊的EC2。通过了神圣完整的谷歌。没有运气,没有工作。我真的不知道下一步需要测试什么才能运行我的静态文件。

我共享我的本地工作系统Django配置:

settings.py

代码语言:javascript
复制
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ui',
)

TEMPLATE_DIR = (
    os.path.join(BASE_DIR, 'website/ui/templates/'),
)

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "website/ui/static"),
)

现在的问题是,TEMPLATE_DIR运行良好。

index.html

代码语言:javascript
复制
{% load static from staticfiles %}
...
...
<img src="{% static 'images/logo.jpg' %}" width="100" height="100" />
...
...

我在EC2上所做的特定配置是:

我遵循了这个博客的说明:在AWS上部署Django

现在,我的/etc/apache2/sites-enabled包含具有以下数据的test_site.com.conf

代码语言:javascript
复制
WSGIScriptAlias / /home/ubuntu/v1/app-info/app/website/website/wsgi.py
WSGIPythonPath /home/ubuntu/v1/app-info/app/website
<Directory /home/ubuntu/v1/app-info/app/website/website/>
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files>
</Directory>

<Directory /home/ubuntu/v1/app-info/app/website/ui/static>
    Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

和IT只为静态文件提供 Page not found (404)

有人能指导如何解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-18 18:26:04

在做了这么多试验之后,我得出的结论是,主要问题在于APACHE配置。

用以下内容替换/etc/apache2/sites-enabled/test_site.com.conf内容解决了我的问题。

代码语言:javascript
复制
WSGIScriptAlias / /home/ubuntu/v1/website-info/app/website/website/wsgi.py
WSGIPythonPath /home/ubuntu/v1/website-info/app/website

<Directory /home/ubuntu/v1/website-info/app/website/website>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /home/ubuntu/v1/website-info/app/website/ui/static/

<Directory /home/ubuntu/v1/website-info/app/website/ui/static>
    Require all granted
</Directory>

ErrorLog /var/log/apache2/error.log
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25368885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档