mod_wsgi 有两个 python 版本

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

我有一个

Ubuntu-18.04 LTS
EC2,为 django 应用程序提供服务,其中
mysql  Ver 8.0.16
Apache/2.4.29
mod_wsgi/4.6.5
符合
python3.6
。现在,我的目标是在同一个 Ubuntu EC2 服务器中部署一个新的 django 应用程序,它需要
python3.11+
virtualenv 来安装其requirements.txt,现在我在部署新应用程序时遇到问题。

这里有一些其他信息,使用 Pyenv 创建 virtualenvs,mod_wsgi 从源代码安装并使用

./configure --with-python=/home/ubuntu/.pyenv/shims/python3.6

进行编译

部署新的 django 应用程序后,域返回 500 错误,日志如下

api.log

[03/Aug/2023:18:42:14 +0000] "GET / HTTP/1.1" 500 816
[03/Aug/2023:18:43:17 +0000] "GET / HTTP/1.1" 500 816
[03/Aug/2023:18:43:17 +0000] "GET / HTTP/1.1" 500 816
[03/Aug/2023:18:43:17 +0000] "GET / HTTP/1.1" 500 816
[03/Aug/2023:18:43:18 +0000] "GET / HTTP/1.1" 500 816
[03/Aug/2023:18:43:18 +0000] "GET / HTTP/1.1" 500 816

api_error.log

[Thu Aug 03 18:43:18.047679 2023] [wsgi:error] [pid 170353:tid 140404074731072]  mod_wsgi (pid=170353): Failed to exec Python script file '/var/www/project/newdjango/wsgi.py'.
[Thu Aug 03 18:43:18.047724 2023] [wsgi:error] [pid 170353:tid 140404074731072]  mod_wsgi (pid=170353): Exception occurred processing WSGI script '/var/www/project/newdjango/wsgi.py'.
[Thu Aug 03 18:43:18.047795 2023] [wsgi:error] [pid 170353:tid 140404074731072]  Traceback (most recent call last):
[Thu Aug 03 18:43:18.047810 2023] [wsgi:error] [pid 170353:tid 140404074731072]    File "/var/www/project/newdjango/wsgi.py", line 12, in <module>
[Thu Aug 03 18:43:18.047814 2023] [wsgi:error] [pid 170353:tid 140404074731072]      from django.core.wsgi import get_wsgi_application
[Thu Aug 03 18:43:18.047827 2023] [wsgi:error] [pid 170353:tid 140404074731072]  ModuleNotFoundError: No module named 'django'
[Thu Aug 03 18:43:18.180781 2023] [wsgi:error] [pid 170353:tid 140403957233216]  mod_wsgi (pid=170353): Failed to exec Python script file '/var/www/project/newdjango/wsgi.py'.
[Thu Aug 03 18:43:18.180819 2023] [wsgi:error] [pid 170353:tid 140403957233216]  mod_wsgi (pid=170353): Exception occurred processing WSGI script '/var/www/project/newdjango/wsgi.py'.
[Thu Aug 03 18:43:18.180886 2023] [wsgi:error] [pid 170353:tid 140403957233216]  Traceback (most recent call last):
[Thu Aug 03 18:43:18.180900 2023] [wsgi:error] [pid 170353:tid 140403957233216]    File "/var/www/project/newdjango/wsgi.py", line 12, in <module>
[Thu Aug 03 18:43:18.180904 2023] [wsgi:error] [pid 170353:tid 140403957233216]      from django.core.wsgi import get_wsgi_application
[Thu Aug 03 18:43:18.180916 2023] [wsgi:error] [pid 170353:tid 140403957233216]  ModuleNotFoundError: No module named 

这是apache的配置

<VirtualHost *:80>
    ServerName qa.api.domian.com
WSGIDaemonProcess qa.api.domian.com python-home=/home/ubuntu/.pyenv/versions/3.11.3/envs/timesheet_env python-path=/var/www/project
    WSGIProcessGroup qa.api.domian.com
    WSGIApplicationGroup %{GLOBAL}
DocumentRoot /var/www/project

    ErrorLog "${APACHE_LOG_DIR}/api_error.log"
    CustomLog "${APACHE_LOG_DIR}/api.log" common
    LogLevel Warn

    Alias /static /var/www/project/static
    <Directory /var/www/project/static>
        Require all granted
    </Directory>

WSGIScriptAlias / /var/www/project/newdjango/wsgi.py
<Directory "/var/www/project/newdjango">
<Files wsgi.py>
        Require all granted
</Files>
</Directory>

根据mod_wsgi文档和我的研究,该问题是由于virtualenv和mod_wsgi的python版本不同造成的,如果我错了,请纠正我。

现在我的目标是部署 django 应用程序

old-django should use python3.6.8
new-django should use python3.11+

我尝试用

mod_wsgi
 编译 
python3.11

  • 从源下载了最新的
    mod_wsgi/4.9.4
  • ./configure --with-python=/shims/python3.11
  • 制作,进行安装

编译新的 django 应用程序后可以完美运行,但现有的 django 会失败并出现相同的错误

现在任何人都可以建议我解决此问题的步骤。 预先感谢

python django apache mod-wsgi wsgi
1个回答
0
投票

最好的解决方案是使用两个独立的 docker 容器为两个 django 应用程序提供服务,并使用现有的 Apache 服务器作为代理。

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