【问题标题】:404 Error with Static Files served through Django/Apache (Bitnami)通过 Django/Apache (Bitnami) 提供的静态文件出现 404 错误
【发布时间】:2015-11-20 08:27:58
【问题描述】:

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

我的 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>

【问题讨论】:

    标签: python django apache amazon-ec2


    【解决方案1】:

    从文档 (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>
    

    【讨论】:

    • 谢谢。不幸的是,我的堆栈使用的是 2.4.12。无论如何,为了清楚起见,我已经尝试过了,但同样的问题仍然存在。
    【解决方案2】:

    我已经解决了这个问题,尽管不幸的是没有弄清楚确切的问题。我创建了一个具有相同堆栈的空白 EC2 服务器,从所有级别获取 Apache conf 文件并添加了我认为已添加的参数。所以从头开始有效地开始了会议。

    【讨论】:

      猜你喜欢
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 2019-04-12
      相关资源
      最近更新 更多