Two separate django sites in WSGI (root and /two)

杀马特。学长 韩版系。学妹 提交于 2020-01-22 15:15:51

问题


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


回答1:


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}




回答2:


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



来源:https://stackoverflow.com/questions/23394726/two-separate-django-sites-in-wsgi-root-and-two

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!