2017-02-02 74 views
0

我无法从django管理站点访问我的文件。我保存文件没有任何问题,但是当我试图打开它,我得到错误:禁止访问django apache2媒体文件

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

在Django项目设置:

STATIC_URL = '/static/' 

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

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

在项目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) 

在我的虚拟主机中添加了以下设置:

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

但仍然得到这个错误。哪里可以是错误/错误? 编辑1:Apache的错误日志中给出了:

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

尝试'sudo chown -R www-data/path/to/media /' – itzMEonTV

+0

@itzmeontv完成。同样的错误。 –

回答

0

变化/etc/apache2/conf-available/php5-fpm.conf。更换每

Order Deny,Allow 
Deny from all 

Require all granted 

配置必须由a2enconf php5-fpm启用。

编辑

遵循的基本配置:https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/

EDIT 2

做的修改,并添加到您的虚拟主机设置:

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

注意,路径是从根!

+0

但它是django(python)项目。并且在我的/ etc/apache2/conf-available /文件夹中,php5-fpm.conf不存在。 –

+0

我编辑了我的asnwer。 –

+0

在本教程中配置的项目,但错误仍然存​​在。我不kwon为什么当我尝试访问媒体文件我得到403错误,但与静态文件夹一切ok。 –