Django MOD_WSGI 设置? MOD_WSGI Apache2 403 您无权访问此资源

Django MOD_WSGI Settings ? MOD_WSGI Apache2 403 You don't have permission to access this resource

我正在 Ubuntu Server 18.04(VirtualBox) 上测试一个应用,然后才购买 VPS 服务。这是我的 第一次部署 ,即使它是一个测试并且在 VB 上。 我遇到了某种 Apache WSGI 错误。

错误:您无权访问此资源 Apache/2.4.29 (Ubuntu) 服务器位于 192.xxx.xx.xxx 端口 80

在设置 WSGI 之前,我在 8000 端口做了一些 运行 测试,运行 运行良好。当我在服务器上设置 WSGI 时,我无法获得应用 运行ning.

App 和 venv 位于 /home/alp/diricanelektronik 目录下。我的服务器用户名:alp 应用名称是 diricangrup

(我确实更改了 conf 文件并重新启动了 apache 服务) 我的头快要爆炸了。 你是我最后的希望,请帮助我

ufw 状态:

22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)

应用主目录: (/home/alp/diricanelektronik/diricangrup)

├── contact
│   ├── admin.py
│   ├── apps.py
│   ├── forms.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── db.sqlite3
├── diricangrup
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── media
├── references
│   ├── admin.py
│   ├── apps.py
│   ├── forms.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── requirements.txt
├── static
│   ├── css
│   │   ├── mobile.css
│   │   ├── references.css
│   │   └── style.css
├── staticfiles
│   │── css
│      ├── mobile.css
│      ├── references.css
│      └── style.css 
│       
└── templates
    ├── base.html
    ├── includes
    │   ├── footer.html
    │   └── navbar.html
    ├── index.html
    └── references.html

文件权限:

/home/alp
drwxrwxr-x 4 alp  www-data 4096 Nov 24 11:09 diricanelektronik


/home/alp/diricanelektronik

drwxrwxr-x 4 alp www-data 4096 Nov 24 11:09 .
drwxr-xr-x 6 alp alp      4096 Nov 23 22:25 ..
drwxrwxr-x 9 alp www-data 4096 Nov 24 14:27 diricangrup
drwxrwxr-x 6 alp alp      4096 Nov 23 22:41 venv



/home/alp/diricanelektronik/diricangrup

drwxrwxr-x 9 alp www-data   4096 Nov 24 14:27 .
drwxrwxr-x 4 alp www-data   4096 Nov 24 11:09 ..
drwxrwxr-x 4 alp alp        4096 Nov 23 22:16 contact
-rw-rw-r-- 1 alp www-data 139264 Nov 24 11:44 db.sqlite3
drwxrwxr-x 3 alp alp        4096 Nov 23 22:53 diricangrup
-rw-rw-r-- 1 alp alp         689 Nov 23 22:16 manage.py
drwxrwxr-x 2 alp www-data   4096 Nov 24 11:44 media
drwxrwxr-x 4 alp alp        4096 Nov 23 22:16 references
-rw-rw-r-- 1 alp alp         100 Nov 23 22:16 requirements.txt
drwxrwxr-x 6 alp alp        4096 Nov 23 22:16 static
drwxrwxr-x 7 alp alp        4096 Nov 23 22:16 staticfiles
drwxrwxr-x 3 alp alp        4096 Nov 24 11:35 templates



/home/alp/diricanelektronik/diricangrup/diricangrup

drwxrwxr-x 3 alp alp      4096 Nov 23 22:53 .
drwxrwxr-x 9 alp www-data 4096 Nov 24 14:27 ..
-rw-rw-r-- 1 alp alp         0 Nov 23 22:16 __init__.py
drwxrwxr-x 2 alp alp      4096 Nov 23 22:53 __pycache__
-rw-rw-r-- 1 alp alp       415 Nov 23 22:16 asgi.py
-rw-rw-r-- 1 alp alp      3950 Nov 23 22:53 settings.py
-rw-rw-r-- 1 alp alp      1241 Nov 23 22:16 urls.py
-rw-rw-r-- 1 alp alp       415 Nov 23 22:16 wsgi.py

WSGI 配置文件:

        Alias /static /home/alp/diricanelektronik/diricangrup/staticfiles
        <Directory /home/alp/diricanelektronik/diricangrup/staticfiles>
                Require all granted
        </Directory>

        Alias /media /home/alp/diricanelektronik/diricangrup/media
        <Directory /home/alpcusta/diricangrup/media>
                Require all granted
        </Directory>

        <Directory /home/alpcusta/diricanelektronik/diricangrup/diricangrup>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIScriptAlias / /home/alpcusta/diricanelektronik/diricangrup/diricangrup/wsgi.py
        WSGIDaemonProcess django_app python-path=/home/alp/diricanelektronik/diricangrup python-home=/home/alp/diricanelektronik/venv
        WSGIProcessGroup django_app

ALLOWED_HOSTS = ['192.xxx.xx.xxx','127.0.0.1']

我尝试了一些东西但没有用然后我决定删除 apache2libapache2-mod-wsgi-py3 并重新安装。还从服务器中删除了项目文件

要删除:

sudo apt-get purge apache2 libapache2-mod-wsgi-py3

重新安装:

sudo apt-get install apache2 libapache2-mod-wsgi-py3

将项目从 windows 发送到 ubuntu 服务器:

scp -P 22 -r django-project user@ipadress:/home/user

配置文件

cd /etc/apache2/sites-available/ && cp 000-default.conf django.conf && sudo nano django.conf

        Alias /static /home/user/django-project/django-project/staticfiles
        <Directory /home/user/django-project/django-project/staticfiles> 
            Require all granted
        </Directory>


        Alias /media /home/user/django-project/django-project/media
        <Directory /home/user/django-project/django-project/media> 
            Require all granted
        </Directory>

        #
        <Directory /home/user/django-project/django-project/django-project>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>


        WSGIScriptAlias / /home/user/django-project/django-project/django-project/wsgi.py
        WSGIDaemonProcess django_app python-path=/home/user/django-project/django-project python-home=/home/user/django-project/venv
        WSGIProcessGroup django_app

经过这一切

sudo chown :www-data django-project/db.sqlite3 #(make apache the group owner)
sudo chmod 664 django-project/db.sqlite3       
sudo chown :www-data django-project   #main app dir
sudo chmod 775 django-project         #main app dir

sudo chown -R :www-data django-project/media/
sudo chmod -R 775 django-project/media

重启apache2

systemctl reload apache2
sudo service apache2 restart

基本上和我之前做的一样,但是这次成功了(由于文件访问权限而出错