permision否认了django静态文件

时间:2016-03-02 12:29:57

标签: python django mod-wsgi apache2.4

今天我在部署django项目时面临一些问题+ apache2 mod_wsgi

让我们清楚一些事实: 1.这不是我的第一次部署 2.网站对mod_wsgi负责 3."静电"文件夹有777个参数,包括文件和文件夹

我的虚拟主机看起来像这样

<VirtualHost *:80>
    ServerName myproject.com
    AddDefaultCharset UTF-8
    ServerAdmin webmaster@myproject.com
    ServerAlias www.myproject.com   
    DocumentRoot /home/ilyas/open.tm/bin/myproject/

    WSGIScriptAlias / /home/ilyas/open.tm/bin/myproject/myproject/index.wsgi

    <Directory /home/ilyas/open.tm/bin/myproject>
        Order deny,allow  
        Require all granted
    </Directory>

    Alias /static/ /home/ilyas/open.tm/bin/myproject/static/

    <Directory /home/ilyas/open.tm/bin/myproject/static>
        Order allow,deny
        Require all granted
    </Directory>
</VirtualHost>

我的index.wsgi看起来像这样:

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/.virtualenvs/open.tm/local/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/home/ilyas/open.tm/bin')
sys.path.append('/home/ilyas/open.tm/bin/myproject')
sys.path.append('/home/ilyas/open.tm/bin/myproject/static')
sys.path.append('/home/ilyas/open.tm/bin/myproject/myproject')

# Activate your virtual env
activate_env=("/home/ilyas/open.tm/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
application = get_wsgi_application()

和我的settings.py的最终文件部分

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

STATICFILES_DIRS = (
    'static', '/home/ilyas/open.tm/bin/myproject/static/',
    'media', '/home/ilyas/open.tm/bin/myproject/media/',
)

MEDIA_ROOT = os.path.join(BASE_DIR, "static/")

该网站运行良好,我可以浏览页面,我可以访问管理员后端,我可以通过后端添加记录......但STATIC文件不能加载&#34;您没有权限访问/此服务器上的static / image.png。&#34;

Django = 1.9.2 Apache = 2.4.7

1 个答案:

答案 0 :(得分:2)

根据文件:

https://httpd.apache.org/docs/2.4/upgrading.html

2.4:

中不需要这样做
Order allow,deny

尝试删除它?