簡體   English   中英

同一站點,不同的Django項目,通過不同的網址提供服務

[英]Same site, different django projects, served through different url

所以我在:

  • Ubuntu 14.04.3 LTS
  • 阿帕奇/2.4.7
  • 從源代碼構建的最新mod-wsgi-3.4
  • Python 3.4 virtualenv
  • 的Django 1.86

我在不同的位置有2個django項目:

  • / home / admin / myproject /
  • / home / boba / bobaproject /

因此,目錄位於不同的用戶下。

我正嘗試在www.example.com上為myproject服務,並在www.example.com/boba上為boba服務。

我遵循了https://gun.io/blog/how-to-install-multiple-django-sites-on-the-same-server/並設置了我的Apache配置文件:

<VirtualHost *:80>
    ServerAdmin a@b.com
    ServerName example.com
    DocumentRoot /var/www/example.com/public_html

    WSGIScriptAlias /boba /home/boba/bobaproject/website/wsgi.py
    WSGIDaemonProcess boba python-path=/home/boba/bobaproject:/home/boba/bobaproject/bbenv/lib/python3.4/site-packages
    WSGIProcessGroup boba
    <Directory /home/boba/bobaproject/website>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static /home/boba/bobaproject/static
    <Directory /home/boba/bobaproject/static>
        Require all granted
    </Directory>

    WSGIScriptAlias / /home/admin/myproject/myproject/wsgi.py
    WSGIDaemonProcess myproject python-path=/home/admin/myproject:/home/admin/myproject/myprojectenv/lib/python3.4/site-packages
    WSGIProcessGroup myproject
    <Directory /home/admin/myproject/myproject>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static /home/admin/myproject/static
    <Directory /home/admin/myproject/static>
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

但是我在www.example.com和www.example.com/boba上都只能得到myproject, 如果我刪除另一個,則兩個站點配置都可以正常工作。 他們在一起沒有。

我聲明wsgi應用程序的順序似乎與myproject是正確的,后者由稍后聲明的基本url提供服務。 波巴是第一

同樣,每個wsgi應用程序都有其自己的WSGIProcessGroup。 這里可能出什么問題了?

我一直在Apache錯誤日志中獲取此信息,不確定是否相關:

[Sat Nov 14 16:46:35.305968 2015] [:error] [pid 31518:tid 139634209957760] AssertionError: 
[Sat Nov 14 16:46:35.366063 2015] [:error] [pid 31518:tid 139634209957760] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sat Nov 14 16:46:35.366107 2015] [:error] [pid 31518:tid 139634209957760] Traceback (most recent call last):
[Sat Nov 14 16:46:35.366123 2015] [:error] [pid 31518:tid 139634209957760]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sat Nov 14 16:46:35.366705 2015] [:error] [pid 31518:tid 139634209957760]     assert tlock is not None
[Sat Nov 14 16:46:35.366726 2015] [:error] [pid 31518:tid 139634209957760] AssertionError: 
[Sat Nov 14 22:16:36.244778 2015] [:warn] [pid 31724:tid 140082293180288] mod_wsgi: Compiled for Python/3.4.0.
[Sat Nov 14 22:16:36.244939 2015] [:warn] [pid 31724:tid 140082293180288] mod_wsgi: Runtime using Python/3.4.3.
[Sat Nov 14 22:16:36.255767 2015] [mpm_worker:notice] [pid 31724:tid 140082293180288] AH00292: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/3.4.3 configured -- resuming normal operations
[Sat Nov 14 22:16:36.255818 2015] [core:notice] [pid 31724:tid 140082293180288] AH00094: Command line: '/usr/sbin/apache2'

謝謝你的幫助。

在查看以下問題后,我似乎已部分解決了此問題: 使用相同的代碼為2個Django網站提供服務

<VirtualHost *:80>
    ServerAdmin a@b.com
    ServerName example.com       

    WSGIScriptAlias /boba /home/boba/bobaproject/website/wsgi.py
    WSGIDaemonProcess boba python-path=/home/boba/bobaproject:/home/boba/bobaproject/bbenv/lib/python3.4/site-packages
    <Location /boba>
        WSGIProcessGroup boba
    </Location>
    <Directory /home/boba/bobaproject/website>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static /home/boba/bobaproject/static
    <Directory /home/boba/bobaproject/static>
        Require all granted
    </Directory>

    WSGIScriptAlias /myproject /home/admin/myproject/myproject/wsgi.py
    WSGIDaemonProcess myproject python-path=/home/admin/myproject:/home/admin/myproject/myprojectenv/lib/python3.4/site-packages
    <Location /myproject >
        WSGIProcessGroup myproject
    </Location>
    <Directory /home/admin/myproject/myproject>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static /home/admin/myproject/static
    <Directory /home/admin/myproject/static>
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

使用WSGIProcessGroup周圍的Location標簽可以在www.example.com/boba和www.example.com/myproject上給我django應用程序

但我仍希望在我還沒有想到的基本URL example.com上使用myproject應用程序。

注意:不需要刪除DocumentRoot。 保留該名稱將導致從基本URL www.example.com的文檔根文件夾提供原始的舊HTML文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM