相同的网站,不同的django项目,通过不同的网址提供服务

时间:2015-11-14 16:40:32

标签: python django apache apache-config

所以我在:

  • Ubuntu 14.04.3 LTS
  • Apache / 2.4.7
  • 最新的mod-wsgi-3.4源于
  • Python 3.4 virtualenv
  • Django 1.86

我在不同地点有2个django项目:

  • /家/管理/ myproject的/
  • /家庭/波巴/ 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提供的。 boba是第一个

此外,每个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'

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在查看这个问题之后,我似乎已经部分地解决了这个问题:Serving 2 django sites with the same code

<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应用程序

但我仍然更喜欢基本网址example.com上的myproject应用 我还没弄明白。

注意:不需要删除DocumentRoot。保留它将导致从基本URL www.example.com的文档根文件夹提供普通的旧HTML文档