5

After hours of trying I've decided to give in and ask SO for help :)

I have two Django 1.6 sites running on Apache2 on Debian 7. I have one vhost.

I want the root domain for the vhost to go to one django site (example: mydomain.com), and a separate alias for the second site (example: mydomain.com/two).

I can get two alias to work like below:

    WSGIDaemonProcess test1 python-path=/usr/local/projects/project_one:/usr/local/virtualenvs/project/lib/python2.7/site-packages
    WSGIScriptAlias /one /usr/local/projects/project_one/project_one/wsgi.py
    <Location /one>
            WSGIProcessGroup test1
    </Location>

    WSGIDaemonProcess test2 python-path=/usr/local/projects/project_two:/usr/local/virtualenvs/project/lib/python2.7/site-packages
    WSGIScriptAlias /two /usr/local/projects/project_two/project_two/wsgi.py
    <Location /two>
            WSGIProcessGroup test2
    </Location>

This will work if I use the following domains:

http://mydomain.com/one/

http://mydomain.com/two/

But if I want to use the root (mydomain.com) and another (mydomain.com/two), it will not work:

    WSGIDaemonProcess test1 python-path=/usr/local/projects/project_one:/usr/local/virtualenvs/project/lib/python2.7/site-packages
    WSGIScriptAlias / /usr/local/projects/project_one/project_one/wsgi.py
    <Location />
            WSGIProcessGroup test1
    </Location>

    WSGIDaemonProcess test2 python-path=/usr/local/projects/project_two:/usr/local/virtualenvs/project/lib/python2.7/site-packages
    WSGIScriptAlias /two /usr/local/projects/project_two/project_two/wsgi.py
    <Location /two>
            WSGIProcessGroup test2
    </Location>

I believe it is not working because it's trying to run site one with site two's WSGI file: WSGI script '/usr/local/projects/project_one/project/wsgi.py'.

My question is how can I get the second attempt to work so mydomain.com goes to one project, and mydomain.com/two goes to another....

I originally followed this post to get to where I am, but not been able to find anything to help me get round this roadblock.

Appreciate the support, Mark

Community
  • 1
  • 1
LondonAppDev
  • 8,501
  • 8
  • 60
  • 87

2 Answers2

4

Try add the options "process-group" and "application-group" in the WSGIScriptAlias directive:

WSGIScriptAlias / /usr/local/projects/project_one/project_one/wsgi.py process-group=test1 application-group=%{GLOBAL}

...

WSGIScriptAlias /two /usr/local/projects/project_two/project_two/wsgi.py process-group=test2 application-group=%{GLOBAL}

Dilvane Zanardine
  • 2,118
  • 3
  • 23
  • 23
  • This works great, how did you find out that `process-group` and `application-group` can be passed to `WSGIScriptAlias`? They are not described in the [official mod_wsgi docs](https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIScriptAlias.html). I had the same problem as OP when defining them inside ``. It seems there is a problem when `Alias` and `Location` are both targeting `/`. Maybe some Apache precedence rules? – rszalski Sep 15 '16 at 09:07
  • 1
    I think I found it here: http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-django.html A post from Graham Dumpleton's blog. – Dilvane Zanardine Jan 31 '17 at 02:04
  • You deserve a higher ranking on Google! – Dunatotatos Feb 13 '17 at 18:38
0

Maybe a bit late but you can change the order of these wsgi and it should work fine (worked for my two wsgi flask apps). When you first use root it just recognize all addresses as root subdomains, and ignore second Alias. Just make /two your first address and than root:

WSGIDaemonProcess test2 python-path=/usr/local/projects/project_two:/usr/local/virtualenvs/project/lib/python2.7/site-packages
WSGIScriptAlias /two /usr/local/projects/project_two/project_two/wsgi.py
<Location /two>
        WSGIProcessGroup test2
</Location>

WSGIDaemonProcess test1 python-path=/usr/local/projects/project_one:/usr/local/virtualenvs/project/lib/python2.    7/site-packages
WSGIScriptAlias / /usr/local/projects/project_one/project_one/wsgi.py
<Location />
        WSGIProcessGroup test1
</Location>

Maybe someone will find it helpful

Wojciech
  • 34
  • 6