通过Django / Apache(Bitnami)提供静态文件的404错误

时间:2015-08-26 10:33:15

标签: python django apache amazon-ec2

我在EC2上的生产中尝试访问我的django应用程序上的静态文件时收到404错误,尽管它在Vbox中的相同Bitnami堆栈中进行了绝对罚款。 Alias中的httpd.conf条目适用于robots.txtfavicon.ico - 我可以正确访问它们。但是,我似乎无法使用/static条目(即在所有网页上)访问Alias中的任何特定内容。

我的apache日志中没有出现任何关于被服务器配置/等阻止的错误,并且static文件夹上的权限(暂时)设置为777并且没有帮助。我做错了什么?

我的STATIC_ROOT是/opt/bitnami/apps/django/django_projects/data_dashboard/project/static

我的httpd.conf文件如下所示:

<Directory /opt/bitnami/apps/django/django_projects/data_dashboard/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIScriptAlias / /opt/bitnami/apps/django/django_projects/data_dashboard/project/project/wsgi.py

<Directory "/opt/bitnami/apps/django/django_projects/data_dashboard/project/static">
    Require all granted
</Directory>


Alias /static /opt/bitnami/apps/django/django_projects/data_dashboard/project/static
Alias /robots.txt /opt/bitnami/apps/django/django_projects/data_dashboard/project/static/robots.txt
Alias /favicon.ico /opt/bitnami/apps/django/django_projects/data_dashboard/project/static/favicon.ico

我的httpd-vhosts.conf

<VirtualHost *:80>
ServerName ec2-xx-xx-xxx-xx.eu-west-1.compute.amazonaws.com

Include "/opt/bitnami/apps/django/django_projects/data_dashboard/project/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
ServerName ec2-xx-xx-xxx-xx.eu-west-1.compute.amazonaws.com
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/django/django_projects/data_dashboard/project/conf/certs/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/django/django_projects/data_dashboard/project/conf/certs/server.key"

Include "/opt/bitnami/apps/django/django_projects/data_dashboard/project/conf/httpd-app.conf"

我的http-app.conf

<IfDefine !IS_DJANGOSTACK_LOADED> 
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack   processes=2 threads=15    display-name=%{GROUP}
</IfDefine> 

<Directory     "/opt/bitnami/apps/django/django_projects/data_dashboard/project/project">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>

WSGIProcessGroup wsgi-djangostack

WSGIApplicationGroup %{GLOBAL}
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>

</Directory>



<Directory "/opt/bitnami/python/lib/python2.7/site-packages/django">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>

</Directory>

1 个答案:

答案 0 :(得分:0)

从文档(https://wiki.bitnami.com/BitNami_Cloud_Hosting/Base_stack)看,Amazon EC2似乎使用Apache 2.2.29版。您应该更改httpd.conf以涵盖该版本和其他设置中的版本

<Directory /opt/bitnami/apps/django/django_projects/data_dashboard/project/static>
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>
</Directory>