提问人:Balaji Gandham 提问时间:8/4/2023 更新时间:8/4/2023 访问量:19
mod_wsgi有两个 python 版本
mod_wsgi with two python versions
问:
我有一个 EC2 为 django 应用程序提供服务,并遵守了。现在,我的目标是在同一个 Ubuntu EC2 服务中部署一个新的 django 应用程序,它需要 virtualenv 来安装其要求 .txt,现在我在部署新应用程序时遇到了问题。Ubuntu-18.04 LTS
mysql Ver 8.0.16
Apache/2.4.29
mod_wsgi/4.6.5
python3.6
python3.11+
以下是一些其他信息,使用 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文档和我的研究,该问题是由于 Python 版本的 virtualenv 和 mod_wsgi 的差异造成的,如果我错了,请纠正我。
现在我的目标是部署 django 应用程序和old-django should use python3.6.8
new-django should use python3.11+
我尝试编译 withmod_wsgi
python3.11
- 从源代码下载最新
mod_wsgi/4.9.4
- ./configure --with-python=/shims/python3.11
- make, make install
编译后,新的 Django 应用程序可以正常工作,但现有的 Django 会失败并出现相同的错误
现在任何人都可以向我建议解决此问题的步骤。 提前致谢
答:
最好的解决方案是用两个独立的 docker 容器为两个 django 应用程序提供服务,并使用现有的 Apache 服务器作为代理。
评论