问题描述
我正在尝试将旧的Django应用程序(1.7)部署到Debian上的Apache2服务器。我终于可以在./manage.py runserver
上运行该应用程序,但是在使mod-wsgi
正常工作方面没有成功。我从来没有用Python编写过服务器端应用程序,所以我可能会遗漏一些明显的东西。
这些是我遵循的步骤
- 我尝试过的一切都是使用
/usr/bin/python
,它是2.7-我知道,我应该使用virtuelenv
,但是我不想给整个事情增加更多的复杂性(因为我不熟悉) - 用
mod-wsgi
安装了apt-get install libapache2-mod-wsgi
- 将以下配置添加到/etc/apache2/mods-enabled/wsgi.conf
- 重新启动Apache2
<IfModule mod_wsgi.c>
WsgiScriptAlias / /home/rosasystem.pl/public_html/rosasystem/rosasystem/wsgi.py
WsgiPythonHome /usr/bin/python
WsgiPythonPath /home/rosasystem.pl/public_html/rosasystem
LogLevel warn
<Directory /home/rosasystem.pl/public_html/rosasystem/rosasystem>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
</IfModule>
此后,我一直在error.log
中收到此错误消息-我搜索过的大多数内容都表明mod-wsgi
与系统/ virtualenv Python版本之间存在Python版本差异。这没有任何意义,因为所有内容都是Python 2.7。
[Tue Oct 06 15:13:42.946626 2020] [mpm_event:notice] [pid 17059:tid 139874785088640] AH00489: Apache/2.4.38 (Debian) mod_fcgid/2.3.9 OpenSSL/1.1.1g mod_wsgi/4.6.5 Python/2.7 configured -- resuming normal operations
[Tue Oct 06 15:13:42.946650 2020] [core:notice] [pid 17059:tid 139874785088640] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 06 15:13:42.951277 2020] [wsgi:warn] [pid 17061:tid 139874785088640] mod_wsgi (pid=17061): Python home /usr/bin/python is not a directory. Python interpreter may not be able to be initialized correctly. Verify the supplied path.
[Tue Oct 06 15:13:42.951531 2020] [wsgi:warn] [pid 17062:tid 139874785088640] mod_wsgi (pid=17062): Python home /usr/bin/python is not a directory. Python interpreter may not be able to be initialized correctly. Verify the supplied path.
ImportError: No module named site
在这一点上,我很困。我可以尝试什么新东西?
解决方法
site-packages
路径应添加到WSGIPythonPath
,仅获取适用于您系统的正确路径
<IfModule mod_wsgi.c>
WSGIScriptAlias / /home/rosasystem.pl/public_html/rosasystem/rosasystem/wsgi.py
WSGIPythonHome /usr/bin/python
WSGIPythonPath '/home/rosasystem.pl/public_html/rosasystem;/usr/lib/python2.7/dist-packages'
LogLevel warn
<Directory /home/rosasystem.pl/public_html/rosasystem/rosasystem>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
</IfModule>