gpt4 book ai didi

python - 权限被拒绝的 Django 静态文件

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:03 25 4
gpt4 key购买 nike

今天我在部署 django 项目 + apache2 mod_wsgi 时遇到了一些问题

让我们澄清一些事实:1. 这不是我第一次部署2. 站点正在响应 mod_wsgi3.“静态”文件夹有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/image.png在此服务器上。”

Django = 1.9.2 Apache = 2.4.7

最佳答案

根据文档:

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

这在 2.4 中不需要:

Order allow,deny

尝试删除它?

关于python - 权限被拒绝的 Django 静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35747304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com