![](/img/trans.png)
[英]aws ec2 not serving static files in a django react application
[英]Amazon EC2 Django Static Files configuration
昨天配置了Amazon EC2。 通过神圣完整的Google。 没有运气没有工作。 我真的不确定下一步要测试什么才能运行我的静态文件。
我共享工作的本地系统Django配置:
settings.py
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
{% 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
,其中包含以下数据:
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
并且它给了我 Page not found (404)
仅用于静态文件
有人可以指导如何解决它:|
好了,在进行了许多次试验之后,我得出的结论是,主要问题在于APACHE配置。
用下面的内容替换/etc/apache2/sites-enabled/test_site.com.conf
内容可以解决我的问题。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.