apache 使用pyenv运行mod_wsgi

qmb5sa22  于 2023-06-24  发布在  Apache
关注(0)|答案(1)|浏览(222)

我想在Apache服务器上运行一个Python Web应用程序。安装mod_wsgi:sudo apt-get install libapache2-mod-wsgi
这是我的网站配置文件:

  1. <virtualhost *:80>
  2. ServerName 192.168.60.144
  3. WSGIDaemonProcess myapp.dev processes=1 threads=1 python-home="/home/user/.pyenv/versions/3.6.1" python-path="/home/user/API" home='/home/user/API'
  4. WSGIProcessGroup myapp.dev
  5. WSGIScriptAlias / /home/user/API/config_files/myservice.wsgi.py
  6. <Directory /home/user/API>
  7. Order allow,deny
  8. Allow from all
  9. </Directory>
  10. DocumentRoot /home/user/API/myservice/testdir
  11. <Directory />
  12. AllowOverride None
  13. Require all granted
  14. </Directory>
  15. </virtualhost>

但是,当尝试访问Web应用程序时,我得到“内部服务器错误”。这是来自日志的错误:
[Mon Mar 12 13:34:04.054636 2018][wsgi:error][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] mod_wsgi(pid = 6762):无法将目标WSGI脚本“/home/user/API/config_files/www.example.com”加载为Python模块。myservice.wsgi.py处理WSGI脚本“/home/user/API/config_files/www.example.com”时发生异常。[Mon Mar 12 13:34:04.054693 2018][wsgi:error][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] Traceback(most recent call last):[3月12日星期一13:三十四:04.054717 2018][wsgi:错误][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] File "/home/user/API/config_files/www.example.com ",line 6,in [Mon Mar 12 13:三十四:04.054752 2018][wsgi:错误][pid 6762:tid 139768980616960][remote 10.10.30.13:34438]从pathlib导入路径[Mon Mar 12 13:三十四:04.054775 2018][wsgi:错误][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] ImportError:* * 没有名为pathlib的模块**myservice.wsgi.py '. [Mon Mar 12 13:34:04.054693 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] Traceback (most recent call last): [Mon Mar 12 13:34:04.054717 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] File "/home/user/API/config_files/myservice.wsgi.py ", line 6, in [Mon Mar 12 13:34:04.054752 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] from pathlib import Path [Mon Mar 12 13:34:04.054775 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] ImportError:No module named pathlib
我已经检查了pyenv python安装,它安装了pathlib模块。这意味着可能没有使用正确的Python版本。如何查看使用的Python版本?我是否错误地设置了python-home属性?

jei2mxaa

jei2mxaa1#

你不能在pyenv环境中使用mod_wsgi的系统打包版本。mod_wsgi必须针对所使用的特定Python安装/版本进行编译。当使用pyenv时,它是一个单独的Python安装,而不是正在使用的系统Python。你应该使用pip install方法来安装为pyenv创建的Python安装编译的mod_wsgi。请确保在安装pyenv时启用了共享库。

IOW,卸载系统打包版本的mod_wsgi,然后使用pip install方法安装mod_wsgi并配置Apache使用它。参见:

具体来说,请参阅Connecting into Apache installation部分,了解如何将pip安装的mod_wsgi加载到Apache中。即修改/etc/apache2/mods-available/wsgi.load中的路径,使其指向虚拟环境中的mod_wsgi-<version>.so文件。

相关问题