简体   繁体   中英

Forbidden access for django apache2 media files

I have trouble with access my files from django admin site. I save files without any trouble, but when I try open it, I get error:

Forbidden
You don't have permission to access /media/file.pdf on this server.

In django project settings:

STATIC_URL = '/static/'

STATIC_ROOT = '/full/path/to/static/'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

In project urls.py:

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

In my virtualhost I added this settings:

 Alias /static/ "/static/folder/"
 Alias /media/ "/meida/folder/" 
 <Directory "/static/folder">
    Require all granted
 </Directory>
 <Directory "/media/folder">
    Require all granted
 </Directory>

But still get this error. Where can be bug/mistake? Edit 1: apache error log gives:

client denied by server configuration: /etc/apache2/home

Change /etc/apache2/conf-available/php5-fpm.conf. Replace every

Order Deny,Allow
Deny from all

to

Require all granted

The configuration has to be enabled by a2enconf php5-fpm .

EDIT

Follow the Basic Configuration: https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/

EDIT 2

Do the changes and add this to your virtualhost settings:

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

Note that the path is from the root!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM