wildcard subdomains pointing to different virtualenv environments

32 views
Skip to first unread message

Aljosa Mohorovic

unread,
Jun 15, 2010, 4:50:22 PM6/15/10
to modwsgi
i'm trying to create mod_wsgi configuration that support public site/
wsgi application and development releases.
idea is that for every release i create a clean python environment
(using virtualenv) under /var/www/wsgi/www.example.com/releases/
---
$ ls /var/www/wsgi/www.example.com/releases/
r1 r2 r3 r4 r5
---
and using pip install new release (and dependencies) into new
virtualenv/python environment.

if apache vhost configuration contains:
---
ServerName www.example.com
ServerAlias r*.www.example.com

WSGIScriptAlias / /var/www/wsgi/www.example.com/project.wsgi
---
i can easily add:
>> site.addsitedir("/var/www/wsgi/www.example.com/current/env/lib/python2.6/site-packages/")
where /var/www/wsgi/www.example.com/current/ is symlink to latest
release (example: /var/www/wsgi/www.example.com/releases/r5/).

so www.example.com will display latest release but i also would like
to access other releases via r(\d).www.example.com.
i can get SERVER_NAME in project.wsgi from environ but i think
sys.path will get mixed if i try to resolve this in project.wsgi or am
i wrong?

i'm open to any suggestion, i would only like to preserve separate
virtualenv/python environments for each release.
other than that i have no problems in having project.wsgi for each
release and in apache vhost configuration point to different wsgi
files for each subdomain.

any ideas, tips, comments are appreciated.

Aljosa Mohorovic

Graham Dumpleton

unread,
Jun 15, 2010, 11:12:45 PM6/15/10
to mod...@googlegroups.com

Does each revision have its own set of static files which also need to
be mapped explicitly by Apache in order to be served up?

Graham

Ian Bicking

unread,
Jun 15, 2010, 11:18:47 PM6/15/10
to mod...@googlegroups.com
It's a little involved (well, a lot involved), but Silver Lining does this: http://bitbucket.org/ianb/silverlining/src/tip/silverlining/server-root/etc/apache2/sites-enabled/wsgi_runner

Basically you need a WSGIApplicationGroup for each environment, and in my case I use one wsgi file (http://bitbucket.org/ianb/silverlining/src/tip/silverlining/mgr-scripts/master-runner.py) that uses environ['HTTP_HOST'] to find and activate the environment.


--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To post to this group, send email to mod...@googlegroups.com.
To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.




--
Ian Bicking  |  http://blog.ianbicking.org

Aljosa Mohorovic

unread,
Jun 16, 2010, 5:09:06 AM6/16/10
to modwsgi
On Jun 16, 5:12 am, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> Does each revision have its own set of static files which also need to
> be mapped explicitly by Apache in order to be served up?

yes, static files are also different for each revision.
i use a python package to bundle static files and then create a
symlink to /media/static/ where /media/ is configured in apache vhost
config but a better approach is needed since this doesn't work for
each revision.
mapping static files explicitly by Apache for each revision would be
excellent.

Aljosa

Aljosa Mohorovic

unread,
Jun 16, 2010, 5:20:01 AM6/16/10
to modwsgi
On Jun 16, 5:18 am, Ian Bicking <i...@colorstudy.com> wrote:
> It's a little involved (well, a lot involved), but Silver Lining does this:http://bitbucket.org/ianb/silverlining/src/tip/silverlining/server-ro...
>
> Basically you need a WSGIApplicationGroup for each environment, and in my
> case I use one wsgi file (http://bitbucket.org/ianb/silverlining/src/tip/silverlining/mgr-scrip...)
> that uses environ['HTTP_HOST'] to find and activate the environment.

i did look at toppcloud when it started but if i understood correctly
it was focused on rackspacecloud and i'm targeting amazon services.
also, i'm using fabric to manage python2.6 on ubuntu karmic and lucid
(official releases for aws ec2) with postgres 8.4, apache/mod_wsgi and
rabbitmq.
does silverlining target specific releases based on linux distro
available at rackspacecloud or something else?
i'll take a look at your workflow, i'm sure i'll find something
useful.

Aljosa

p.s.
currently i do use both rackspacecloud and amazon services but i'm
moving towards amazon because it has much more options and is
available in europe

Graham Dumpleton

unread,
Jun 16, 2010, 6:05:01 AM6/16/10
to mod...@googlegroups.com

Have a read of the thread:

http://groups.google.com/group/modwsgi/browse_frm/thread/d0b1d5eb77f56d77

There are various suggestions in there of how to do the sort of thing
you want, including trying to provide a way to allow instances for a
specific revision to be delegated to their own daemon process group to
keep them distinct from others.

Especially see the VirtualDocumentRoot examples. Indicate whether you
have any restrictions on being able to use VirtualDocumentRoot and
then we can go from there or refine that method.

Graham

Aljosa Mohorovic

unread,
Jun 17, 2010, 4:48:22 AM6/17/10
to modwsgi
On Jun 16, 12:05 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> Have a read of the thread:
>
>  http://groups.google.com/group/modwsgi/browse_frm/thread/d0b1d5eb77f5...
>
> There are various suggestions in there of how to do the sort of thing
> you want, including trying to provide a way to allow instances for a
> specific revision to be delegated to their own daemon process group to
> keep them distinct from others.
>
> Especially see the VirtualDocumentRoot examples. Indicate whether you
> have any restrictions on being able to use VirtualDocumentRoot and
> then we can go from there or refine that method.

i need couple of days to read the docs and test this, should i post
here when i figure out how this works of should i start a new thread?

Aljosa

Graham Dumpleton

unread,
Jun 17, 2010, 4:54:36 AM6/17/10
to mod...@googlegroups.com
Followup to this thread is okay.

Ian Bicking

unread,
Jun 17, 2010, 5:19:40 AM6/17/10
to mod...@googlegroups.com
On Wed, Jun 16, 2010 at 4:20 AM, Aljosa Mohorovic <aljosa.m...@gmail.com> wrote:
On Jun 16, 5:18 am, Ian Bicking <i...@colorstudy.com> wrote:
> It's a little involved (well, a lot involved), but Silver Lining does this:http://bitbucket.org/ianb/silverlining/src/tip/silverlining/server-ro...
>
> Basically you need a WSGIApplicationGroup for each environment, and in my
> case I use one wsgi file (http://bitbucket.org/ianb/silverlining/src/tip/silverlining/mgr-scrip...)
> that uses environ['HTTP_HOST'] to find and activate the environment.

i did look at toppcloud when it started but if i understood correctly
it was focused on rackspacecloud and i'm targeting amazon services.
also, i'm using fabric to manage python2.6 on ubuntu karmic and lucid
(official releases for aws ec2) with postgres 8.4, apache/mod_wsgi and
rabbitmq.
does silverlining target specific releases based on linux distro
available at rackspacecloud or something else?
i'll take a look at your workflow, i'm sure i'll find something
useful.

It targets Ubuntu Karmic (probably Lucid sometime in the future).  I don't know of any substantive differences between the Linux different providers give, I'd assume Ubuntu Karmic on Rackspace would be the same as on Amazon.  Some of the cloud management tools (e.g., to create a server) haven't been entirely abstracted beyond Rackspace, but once a server is created it doesn't matter how, so it would work fine with Amazon.
 
Otherwise your stack is nearly identical to what Silver Lining does, except there is not (yet) any RabbitMQ setup/configuration.

Aljoša Mohorović

unread,
Jul 6, 2010, 11:15:08 AM7/6/10
to mod...@googlegroups.com
On Thu, Jun 17, 2010 at 10:54 AM, Graham Dumpleton
<graham.d...@gmail.com> wrote:
> Followup to this thread is okay.

i didn't have time to properly read docs and test configurations (hope
i'll have time next week) but i have some questions and would
appreciate any comments.

silverlining approach to use a single wsgi file to handle app
revisions is interesting and i was wondering if anybody would like to
comment pros/cons on using apache config vs. wsgi file to handle app
revisions?

i've been playing with VirtualDocumentRoot and it looks ok but i can't
find what is the problem when used instead of VirtualHost?
i did get an impression that for some reason i shouldn't mix
VirtualHost and VirtualDocumentRoot although i'm not sure why (am i
just wrong here?).
if i use VirtualDocumentRoot as default config can individual domains
(or subdomains) be configured separately?

Aljosa

Graham Dumpleton

unread,
Jul 6, 2010, 9:02:24 PM7/6/10
to mod...@googlegroups.com

I think (cant remember for sure), if you are using VirtualDocumentRoot
at global scope in Apache configuration you cant use VirtualHost at
the same time.

If however you need to use VirtualHost, you can still use
VirtualDocumentRoot inside of the VirtualHost to map to varying
document root where you have a ServerAlias that matches multiple names
for that VirtualHost.

Graham

Reply all
Reply to author
Forward
0 new messages