apache WSGI错误:目标WSGI脚本无法作为Python模块加载

lf5gs5x2  于 2023-10-23  发布在  Apache
关注(0)|答案(2)|浏览(270)

我尝试使用apache部署Django应用程序,收到以下错误

  1. [Fri Oct 08 07:55:44.393237 2021] [wsgi:error] [pid 12424:tid 140450959271680] mod_wsgi (pid=12424): Target WSGI script '/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py' cannot be loaded as Python module.
  2. [Fri Oct 08 07:55:44.393281 2021] [wsgi:error] [pid 12424:tid 140450959271680] mod_wsgi (pid=12424): Exception occurred processing WSGI script '/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py'.
  3. [Fri Oct 08 07:55:44.393408 2021] [wsgi:error] [pid 12424:tid 140450959271680] Traceback (most recent call last):
  4. [Fri Oct 08 07:55:44.393430 2021] [wsgi:error] [pid 12424:tid 140450959271680] File "/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py", line 12, in <module>
  5. [Fri Oct 08 07:55:44.393435 2021] [wsgi:error] [pid 12424:tid 140450959271680] from django.core.wsgi import get_wsgi_application
  6. [Fri Oct 08 07:55:44.393446 2021] [wsgi:error] [pid 12424:tid 140450959271680] ModuleNotFoundError: No module named 'django'

我的Apache虚拟主机

  1. <VirtualHost *:80>
  2. DocumentRoot /home/preinstall/hx_preinstaller
  3. ErrorLog ${APACHE_LOG_DIR}/preinstall_error.log
  4. CustomLog ${APACHE_LOG_DIR}/access.log combined
  5. <Directory /home/preinstall/hx_preinstaller/hx_preinstaller>
  6. <Files wsgi.py>
  7. Require all granted
  8. </Files>
  9. </Directory>
  10. <Directory /home/preinstall/hx_preinstaller>
  11. Require all granted
  12. </Directory>
  13. WSGIDaemonProcess preinstall python-path=/home/preinstall/hx_preinstaller:/home/preinstall/.local/lib/python3.6/site-packages
  14. WSGIProcessGroup preinstall
  15. WSGIPassAuthorization On
  16. WSGIScriptAlias / /home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py
  17. </VirtualHost>

我该怎么办?..

lyfkaqu1

lyfkaqu11#

可能是python版本不匹配,或者您没有正确地将python路径添加到appache.conf。去检查这篇文章了解更多关于这个错误-> link

qzlgjiam

qzlgjiam2#

可能下面的解决方案可以为您工作,如果您的服务器使用旧的Python版本,如3.6,并且您更新到3.11,则可能会发生这种情况。以下是我推荐的步骤
1.激活虚拟环境conda环境(如果你使用anaconda更新python)。
1.在该环境中运行“pip install mod_wsgi”
1.调整/apache 2/etc/loadmodule.conf从myvirtualenv中加载新的mod_wsgi
1.重新启动httpd

相关问题