Django wsgi Apache2:'AH01630:服务器配置拒绝客户端'

问题描述 投票:0回答:1

我按照本教程来部署我的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 apache debian mod-wsgi python-3.5
1个回答
0
投票

通过在静态之前添加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并顺利运行。

© www.soinside.com 2019 - 2024. All rights reserved.