【发布时间】:2017-11-09 05:48:40
【问题描述】:
我已按照本教程部署我的 django 项目:https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-debian-8
为什么无法从 apache 加载静态文件?
我正在使用 Debian9、Python3.5 和 Django 1.11
这是我的虚拟主机配置:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/alex/djangoproject/static
<Directory /home/alex/djangoproject/static>
Require all granted
</Directory>
<Directory /home/alex/djangoproject/cpanel>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess djangoproject python-home=/home/alex/djangoproject/djangoprojectenv python-path=/home/alex/djangoproject
WSGIProcessGroup djangoproject
WSGIScriptAlias / /home/alex/djangoproject/cpanel/wsgi.py
</VirtualHost>
`
还有来自 error.log 的 apache 错误:
AH01630: client denied by server configuration /home/alex/djangoproject/static
我的 settings.py 配置与静态 foder 相关
STATIC_URL = '/static/'
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
【问题讨论】:
-
通常运行 Apache 的用户无法访问您的主目录。检查主目录和所有目录的权限,直到文件所在的位置,以确保其他人可读。
-
它可以访问wsgi文件来加载服务器文件,因为www-data组是项目目录的递归所有者。也测试了所有文件的777权限,仍然相同。
-
不只是项目目录及其下的一切。如果父目录(通常 /home 有问题)具有 rwxr-x--- 的权限,即任何人都无法读取,它将无法工作。如果使用 CentOS/RHEL/Fedora,唯一的其他原因是 SELinux 限制。
标签: django apache debian mod-wsgi python-3.5