簡體   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