Forbidden access 403 for django apache2 media files

This problem is usually when you try to publish media files in /home/../ directory. That is an operating system security. 

All media files should be under /var/www/ or on a external hardrive but not in home.

chgrp -R www-data /var/www/

chmod -R g+w /var/www/

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.

 <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

vim /etc/apache2/sites-enabled/default-ssl.conf

 Alias /media/ /var/www/media/
        <Location "/media">
            SetHandler None
            Options -Indexes
            AddType text/html php
        </Location>





Comments