简体   繁体   中英

Same site, different django projects, served through different url

So I am on:

  • Ubuntu 14.04.3 LTS
  • Apache/2.4.7
  • Latest mod-wsgi-3.4 built from source
  • Python 3.4 virtualenv
  • Django 1.86

I have 2 django projects at different locations:

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

So the directories are under different users.

I am trying to serve myproject at www.example.com and serve boba at www.example.com/boba

I followed https://gun.io/blog/how-to-install-multiple-django-sites-on-the-same-server/ and setup my Apache config file:

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

But I am getting only myproject at both www.example.com and www.example.com/boba Individually both site configs do work if I remove the other. Together they dont.

My order of declaring the wsgi applications seem to be correct with myproject which is served by the basic url declared later. boba is first

Also each wsgi application has its own WSGIProcessGroup. What could be going wrong here?

I keep getting this in the Apache error logs, not sure if its relevant:

[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'

Thanks for any help.

I seem to have partially solved this after looking at this question: 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>

Using the Location tag around the WSGIProcessGroup gives me the django apps at www.example.com/boba and www.example.com/myproject

But I still would prefer the myproject app at the base URL example.com That I haven't figured out yet.

Note: Removing DocumentRoot is not needed. Keeping it will cause the plain old HTML docs to be served from the document root folder for the base URL www.example.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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