繁体   English   中英

使用 WSGI 将 Django 1.7 应用程序部署到 Apache2

[英]Deploy Django 1.7 application to Apache2 with WSGI

我正在尝试将旧的 Django 应用程序 (1.7) 部署到 Debian 上的 Apache2 服务器。 我终于能够使用./manage.py runserver运行该应用程序,但是我没有成功让mod-wsgi工作。 我从来没有用 Python 编写过服务器端应用程序,所以我可能会遗漏一些明显的东西。

这些是我遵循的步骤

  1. 我尝试的一切都是使用 2.7 的/usr/bin/python - 我知道,我应该使用virtuelenv但我不想给整个事情增加更多的复杂性(因为我不熟悉它)
  2. 安装mod-wsgiapt-get install libapache2-mod-wsgi
  3. 将以下配置添加到 /etc/apache2/mods-enabled/wsgi.conf
  4. 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搜索的大部分内容都表明mod-wsgi和 system/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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM