【问题标题】:How to deploy Django App on Ubuntu using Apache2 and mod-wsgi-pytho3如何使用 Apache2 和 mod-wsgi-pytho3 在 Ubuntu 上部署 Django 应用程序
【发布时间】:2022-12-30 19:21:01
【问题描述】:

我正尝试按照这篇文章 Link of the article 在 AWS 上部署我的 Django 应用程序。 我做了几乎相同但收到此错误 [Sun Nov 13 16:02:45.432532 2022] [wsgi:error] [pid 116628:tid 140699140834880] [remote 171.78.234.250:51518] ModuleNotFoundError: No module named 'bitssatoshiproject> 这是我的 http conf 文件- `

<VirtualHost *:80>
        ServerAdmin ubuntu@172-31-11-19
        ServerName 172-31-11-19
        ServerAlias 172-31-11-19.com    

        ErrorLog /home/ubuntu/site/logs/error.log
        CustomLog /home/ubuntu/site/logs/access.log combine
        
        <Directory /home/ubuntu/BitsSatoshi/bitssatoshiproject>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>
        WSGIDaemonProcess bits python-home=/home/ubuntu/bitsvenv python-path=/home/ubuntu/BitsSatoshi/
        WSGIProcessGroup bits
        WSGIScriptAlias / /home/ubuntu/BitsSatoshi/bitssatoshiproject/wsgi.py

</VirtualHost>

`

请帮帮我,我已经尝试了很多天了。

我尝试了谷歌上的所有指南,但没有成功,甚至不知道我错了。但是可以肯定的是 wsgi 没有得到我的虚拟环境 python。

【问题讨论】:

    标签: django apache2 django-deployment


    【解决方案1】:

    您好,问题出在第 14 行的 WSGIDaemonProcess 这一行,您没有将 wsgi 指向正确的虚拟环境目录,请检查下面的示例以了解项目结构和 Apache 文件,您可以使用 link 了解更多详细信息

    django_项目
    └── env (所有 ENV 文件)
    ├── 管理.py
    └── my_django_project
    ├── 初始化.py
    ├── 设置.py
    ├── 网址.py
    └── wsgi.py

    文件 Apache 配置文件

    <VirtualHost *:80>
        ServerAdmin admin@djangoproject.localhost
        ServerName djangoproject.localhost
        ServerAlias www.djangoproject.localhost
        DocumentRoot /home/user/django_project
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        Alias /static /home/user/django_project/static
        <Directory /home/user/django_project/static>
            Require all granted
        </Directory>
    
        Alias /static /home/user/django_project/media
        <Directory /home/user/django_project/media>
            Require all granted
        </Directory>
    
        <Directory /home/user/django_project/my_django_project>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    
        WSGIDaemonProcess django_project python-path=/home/user/django_project python-home=/home/user/django_project/env
        WSGIProcessGroup django_project
        WSGIScriptAlias / /home/user/django_project/my_django_project/wsgi.py
    </VirtualHost>
    

    其中 django_project 是主目录,my_django_project 是其中的子目录。分别更改上述代码中的目录。

    为 Django 项目启用虚拟主机文件 一旦我们创建了 djangoproject.conf 文件,我们需要通过键入来启用该虚拟主机文件

    cd /etc/apache2/sites-available
    sudo a2ensite djangoproject.conf
    

    【讨论】:

      猜你喜欢
      • 2017-02-01
      • 2014-04-11
      • 2021-01-21
      • 2018-03-30
      • 2016-03-30
      • 1970-01-01
      • 2014-11-24
      • 2015-11-21
      • 2020-08-02
      相关资源
      最近更新 更多