MOD_WSGI Apache2您无权访问此资源

时间:2020-04-07 00:36:27

标签: django apache mod-wsgi digital-ocean

我正在使用apache2和MOD_WSGI部署Django项目。当我运行服务器时,我无法访问该网站,并且在该网站上收到错误消息,

import re

items = []
s = 'hello "ok and @com" name'
patt = re.compile(r'(".*?")') 

# regex to find quoted strings
match = re.search(patt, s)
if match:
    for item in match.groups():
        items.append(item)

# split on whitespace after removing quoted strings
for item in re.sub(patt, '', s).split():
    items.append(item)

>>>items
['"ok and @com"', 'hello', 'name']

enter image description here 我已经设置了我认为需要的所有内容,例如conf文件

Forbidden
You don't have permission to access this resource.
Apache/2.4.29 (Ubuntu) Server at testnexusstudy.com Port 8081

我已经授予了我认为是apache所需的所有权限,这是我的ls -la

<VirtualHost *:8081>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

#Include conf-available/serve-cgi-bin.conf

Alias /static /root/StudBud1/static
<Directory /root/StudBud1/static>
    Require all granted
</Directory>

Alias /media /root/StudBud1/media
<Directory /root/StudBud1/media>
    Require all granted
</Directory>


<Directory /root/StudBud1/StudBud1>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIScriptAlias / /root/StudBud1/StudBud1/wsgi.py
WSGIDaemonProcess StudBud1 python-path=/root/StudBud1
WSGIProcessGroup StudBud1


</VirtualHost>

希望你们中的一些人对这种错误有经验。

2 个答案:

答案 0 :(得分:1)

出于安全原因,我不会使用或授予对Web服务器的root访问权限。

我将创建一个仅有权访问www-data组的用户,并确保apache也位于该组中。

其中一些命令来自Fedora发行版,因此它们可能与Debian有所不同。

$ adduser deploy
$ vim /etc/group

在/ etc / group中:

www-data:x:1003:apache,deploy

/location/to/vhosts/website.conf(为清晰起见,删除了外部设置)

<VirtualHost *:80>

    Alias /static/ /srv/vhosts/mywebsite/static/
    Alias /media/ /srv/vhosts/mywebsite/media/
    Alias /robots.txt /srv/vhosts/robots.txt

    <Directory /srv/vhosts/mywebsite/path/to/django/configs>
        Require all granted
    </Directory>

    <Directory /srv/vhosts/mywebsite/static>
      Require all granted
    </Directory>

    <Directory /srv/vhosts/mywebsite/media>
      Require all granted
    </Directory>

    <Location "/robots.txt">
      SetHandler None
      Require all granted
    </Location>

    WSGIDaemonProcess mywebsite python-home=/srv/vhosts/mywebsite/.venv python-path=/srv/vhosts/mywebsite/
    WSGIProcessGroup mywebsite
    WSGIScriptAlias / /srv/vhosts/mywebsite/path/to/django/configs/wsgi.py

</VirtualHost>

然后重新启动apache

完成后,请确保将目录提供给用户并分组www-data 作为sudo(-R表示递归)

$ sudo chown -R deploy:www-data /path/to/webroot

答案 1 :(得分:0)

我是一个初学者。 在全新安装中,我必须设置/ var / www / html目录的权限。 默认情况下,它们是-rw ------- 我输入了sudo chmod 775 *,并且功能正常。