Django wsgi Apache2:'AH01630:服务器配置拒绝客户端'
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django wsgi Apache2:'AH01630:服务器配置拒绝客户端'相关的知识,希望对你有一定的参考价值。
我按照本教程来部署我的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')
答案
通过在静态之前添加django项目名称目录来解决这个问题,这样:
Alias /static /home/alex/djangoproject/static
<Directory /home/alex/djangoproject/static>
Require all granted
</Directory>
会变成这样的:
Alias /static /home/alex/djangoproject/"django-project-name(in mycase: cpanel)"/static
<Directory /home/alex/djangoproject/"django-project-name(in mycase: cpanel)"/static>
Require all granted
</Directory>
执行./migrate.py collectstatic,重启apache并顺利运行。
以上是关于Django wsgi Apache2:'AH01630:服务器配置拒绝客户端'的主要内容,如果未能解决你的问题,请参考以下文章