Apache 403 while serving Django static files

两盒软妹~` 提交于 2019-11-28 10:02:12

I faced this issue as well.

i can't place the static files in /var/www as Noah suggested.

Solved by adding to apache2.conf:

<Directory /usr/local/django_apps/myapp/static>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

Another possibility would be a missing trailing slash in the static root directory. The following configuration was resulting in 403 errors:

WSGIPythonPath /home/foo/app/
WSGIPythonHome /home/foo/.envs/foo

<VirtualHost *:80>
    Alias /static/ /home/foo/assets
    ServerAdmin foo@bar.com
    WSGIScriptAlias / /home/foo/app/wsgi.py
    ErrorLog ${APACHE_LOG_DIR}/app_wsgi_error.log
    CustomLog ${APACHE_LOG_DIR}/app_wsgi_access.log combined
    <Directory /home/foo/app/>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    <Directory /home/foo/assets>
        Require all granted
    </Directory>
</VirtualHost>

After adding a trailing slash to /home/foo/assets, everything worked perfectly. I hope that helps future Googlers.

I figured it out. I moved all the files the static and media files to /var/www and apache seems much happier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!