繁体   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