django Web服务器中的403 Forbidden Error

时间:2016-03-30 09:17:39

标签: python django apache ubuntu mod-wsgi

我正在尝试在webserver上部署我的应用程序(使用apache2和mod_wsgi的django)。但是我在运行网站时遇到403禁止错误..(禁止 您无权访问此服务器上的/。 Apache / 2.4.7(Ubuntu)服务器,位于104.131.127.196端口80)。我的Web应用程序的结构如下所示:

CASINOVA
|-- Casinova
|   |-- db.sqlite3
|   |-- index.html
|   |-- manage.py
|   |-- casinova
|   |   |-- __init__.py
|   |   |-- __init__.pyc
|   |   |-- settings.py
|   |   |-- settings.pyc
|   |   |-- urls.py
|   |   |-- urls.pyc
|   |   |-- wsgi.py
|   |   `-- wsgi.pyc
|   `-- static

sudo nano /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
Alias /static /var/www/html/CASINOVA/Casinova/static/
<Directory /var/www/html/CASINOVA/Casinova/static>
Options Indexes FollowSymLinks Includes ExecCGI
Require all granted
</Directory>
<Directory /var/www/html/CASINOVA/Casinova>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>
WSGIDaemonProcess Casinova python-path=/var/www/html/CASINOVA/Casinova:/var/www/html/CASINOVA/venv/Casinova/lib/python2.7/si$
WSGIProcessGroup Casinova
WSGIScriptAlias / /var/www/html/CASINOVA/Casinova/casinova/wsgi.py

ServerName 0.0.0.0
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/CASINOVA/Casinova
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
AddHandler cgi-script .py

sudo vi /etc/apache2/apache2.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
ServerName mydomain.com

vi /etc/hosts.py

127.0.0.1 localhost
104.131.127.196 Casinova
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

#ls -l / var / www / html

drwxr-xr-x 4 root root  4096 Mar 29 08:42 CASINOVA
-rw-r--r-- 1 root root 11510 Mar 30 03:05 index.html
-rw-r--r-- 1 root root    20 Oct 28 01:42 info.php

我发布了文件default.conf,apache2.conf和hosts.py中的内容。那是什么错误?

1 个答案:

答案 0 :(得分:0)

<Directory /var/www/html/CASINOVA/Casinova/static>
Options Indexes FollowSymLinks Includes ExecCGI
Require all granted
</Directory>

我的猜测是,为您的Django目录设置ExecCGI,而不是/static

<Directory /var/www/html/CASINOVA/Casinova>
Options ExecCGI
</Directory>