Apache on Windows & multiple Django apps

328 views
Skip to first unread message

DJ-Tom

unread,
Sep 1, 2014, 8:50:08 AM9/1/14
to django...@googlegroups.com
Hi,

I'm currently trying to get the same Django app running twice under different URLs on the same server.

App 1 ran last year under https://www.sample.com/2013/app and should stay there for reference purposes.

App 2 should run under https://www.sample.com/2014/app and also should use a different code base and different database than last years version.

I tried the following settings in httpd.conf, but regardless if I use the 2013 or 2014 url, I always get the 2013 version of the application...

I also changed the database setting in the 2014 version in settings.py, but it seems as if this is never executed.

what is the correct way to set this up on Windows/Apache?

#
# WSGI / Django Konfiguration
<IfModule wsgi_module>
    WSGIApplicationGroup %{GLOBAL}
   
    WSGIScriptAlias /2013/app "D:/dev/app/app/wsgi.py"
    WSGIScriptAlias /2014/app "D:/dev/app.2014/app/wsgi.py"
   
    WSGIPythonPath "D:/dev/app"

    <Directory D:/dev/app>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>

    <Directory D:/dev/app.2014>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>

    Alias /static "D:/wwwroot/app/static/"
    Alias /static2014 "D:/wwwroot/app.2014/static/"
    Header set X-XSS-Protection 0
</IfModule>

Collin Anderson

unread,
Sep 1, 2014, 1:11:41 PM9/1/14
to django...@googlegroups.com
See the docs on deploying with mod_wsgi:


If multiple Django sites are run in a single mod_wsgi process, all of them will use the settings of whichever one happens to run first. This can be solved with a minor edit to wsgi.py (see comment in the file for details), or by using mod_wsgi daemon mode and ensuring that each site runs in its own daemon process.

DJ-Tom

unread,
Sep 2, 2014, 7:08:30 AM9/2/14
to django...@googlegroups.com
Most likely the docs refer to this section of wsgi.py:

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "spcmanage.settings"

But I already have set this in wsgi.py:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

Daemon mode is not possible as this is only available in NON-Windows environments.

So I'm still stuck with this. I did quite a lot of search for this but apparently nobody knows an answer that actually works.

Tom Evans

unread,
Sep 2, 2014, 7:51:28 AM9/2/14
to django...@googlegroups.com
On Tue, Sep 2, 2014 at 12:08 PM, DJ-Tom <event...@gmail.com> wrote:
> Most likely the docs refer to this section of wsgi.py:
>
>> # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This
>> breaks
>> # if running multiple sites in the same mod_wsgi process. To fix this, use
>> # mod_wsgi daemon mode with each site in its own daemon process, or use
>> # os.environ["DJANGO_SETTINGS_MODULE"] = "spcmanage.settings"
>
>
> But I already have set this in wsgi.py:
> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
>
> Daemon mode is not possible as this is only available in NON-Windows
> environments.
>
> So I'm still stuck with this. I did quite a lot of search for this but
> apparently nobody knows an answer that actually works.
>

The most obvious and simple solution is to not use Windows. Whilst
lots of open source software does work on Windows (to some extent),
almost all of it is not developed, designed or targeted for Windows.
Using Windows will make your life harder, not easier (I've never had
to track down specific binary versions of a python package, for
instance).

The next most simple solution is to not use mod_wsgi, use
mod_proxy_http to proxy to a standalone http server that runs django
in its own wsgi container. Again, your problem here is finding one
that runs well on Windows. uWSGI apparently supports it via Cygwin...

Cheers

Tom

Robert Grant

unread,
Sep 2, 2014, 9:26:46 AM9/2/14
to django...@googlegroups.com
Waitress runs fine on Windows; just install with pip.

DJ-Tom

unread,
Sep 2, 2014, 10:28:52 AM9/2/14
to django...@googlegroups.com


Am Dienstag, 2. September 2014 13:51:28 UTC+2 schrieb Tom Evans:
 
The most obvious and simple solution is to not use Windows.

lol - ever heard of the "box of pandora"? :-)

My knowledge of Linux boxes is very close to zero - so setting up a server that is not based on Windows would be the most complicated solution for me.

Apart from that, the box on which all of this needs to be run also runs a different application server which is Windows-only.

Thomas

Collin Anderson

unread,
Sep 2, 2014, 11:45:37 AM9/2/14
to django...@googlegroups.com
setdefault is what's causing your trouble. Change it to an explicit:

os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings'

DJ-Tom

unread,
Sep 2, 2014, 11:50:50 AM9/2/14
to django...@googlegroups.com

*facepalm*... honestly, I did not spot the difference, i believed the line I had was right!!!

thanks anyways, I will try that tomorrow.
Message has been deleted

Tom Evans

unread,
Sep 3, 2014, 7:57:46 AM9/3/14
to django...@googlegroups.com
This is why I gave you two solutions. See solution 2.

Cheers

Tom

DJ-Tom

unread,
Sep 5, 2014, 10:28:03 AM9/5/14
to django...@googlegroups.com
Well.... that seems much too complicated just for running variations of the same application twice. There all kinds of stuff running on that server and adding a proxy to it would be a nightmare to check if everything still works.

What a pity, Django is such a powerful tool, but lacks easy deployment.

Robert Grant

unread,
Sep 5, 2014, 10:35:29 AM9/5/14
to django...@googlegroups.com
I just run it on Windows with foreman start (the Heroku toolbelt) and give it Waitress as a server.

Tom Evans

unread,
Sep 5, 2014, 10:38:30 AM9/5/14
to django...@googlegroups.com
On Fri, Sep 5, 2014 at 3:28 PM, DJ-Tom <event...@gmail.com> wrote:
> Well.... that seems much too complicated just for running variations of the
> same application twice. There all kinds of stuff running on that server and
> adding a proxy to it would be a nightmare to check if everything still
> works.
>
> What a pity, Django is such a powerful tool, but lacks easy deployment.
>

Trolling? Django is deployed in the same way as most Python
applications on all platforms, as a WSGI container. There are vast
numbers of popular web servers that host WSGI containers, but they
mainly do not support Windows as well as *nix.

Cheers

Tom

Collin Anderson

unread,
Sep 5, 2014, 1:39:15 PM9/5/14
to django...@googlegroups.com
You could also ask for tips on the modwsgi list which may have a good solution.
Reply all
Reply to author
Forward
0 new messages