Replacing SCGI with mod_wsgi

3 views
Skip to first unread message

Ksenia

unread,
Feb 5, 2010, 11:31:34 AM2/5/10
to modwsgi
Greetings,

Currently we have 300+ virtual hosts that are using the same Python
process. The connection is done with SCGI. In every VirtualHost we
have:

<VirtualHost "*:80">
ServerName myservername.com
…:
SCGIMount / 127.0.0.1:8080

</VirtualHost>

The application can distinguish what site is requested based on the
hostname in the environ. Python process spawns threads when needed.


I wonder how the same setup can be achieved with mod_wsgi? I couldn't
find an example of multiple VirtualHosts using one global Python
process. It seems that you always have to have 1 process per
VirtualHost. I hope I am wrong on this :)

Thanks
Ksenia.

Jason Garber

unread,
Feb 5, 2010, 10:50:06 PM2/5/10
to mod...@googlegroups.com
Hi Ksenia,

Yes, this is possible.  What you need to do is run a single DaemonProcess named, say, "Primary".  Then within each VirtualHost, you need WSGIProcessGroup that refers to "Primary".

Something like this:

   WSGIApplicationGroup %{GLOBAL}
   WSGIDaemonProcess Primary threads=15 python-path=/foo/bar/Python

   <VirtualHost *:80>
       ServerName foo1.com
       WSGIProcessGroup Primary
       WSGIScriptAlias /User /foo/bar/app.wsgi
   </VirtualHost>
   <VirtualHost *:80>
       ServerName foo2.com
       WSGIProcessGroup Primary
       WSGIScriptAlias /User /foo/bar/app.wsgi
   </VirtualHost>

The best thing would be to take a detailed look at these links:
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess

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


Graham Dumpleton

unread,
Feb 7, 2010, 5:37:42 PM2/7/10
to mod...@googlegroups.com
On 6 February 2010 14:50, Jason Garber <bo...@gahooa.com> wrote:
> Hi Ksenia,
> Yes, this is possible.  What you need to do is run a single DaemonProcess
> named, say, "Primary".  Then within each VirtualHost, you need
> WSGIProcessGroup that refers to "Primary".
> Something like this:
>    WSGIApplicationGroup %{GLOBAL}
>    WSGIDaemonProcess Primary threads=15 python-path=/foo/bar/Python
>    <VirtualHost *:80>
>        ServerName foo1.com
>        WSGIProcessGroup Primary
>        WSGIScriptAlias /User /foo/bar/app.wsgi
>    </VirtualHost>
>    <VirtualHost *:80>
>        ServerName foo2.com
>        WSGIProcessGroup Primary
>        WSGIScriptAlias /User /foo/bar/app.wsgi
>    </VirtualHost>

You can actually put the WSGIProcessGroup outside of the VirtualHost directive.

Thus:

WSGIDaemonProcess Primary threads=15 python-path=/foo/bar/Python
WSGIProcessGroup Primary
WSGIApplicationGroup %{GLOBAL}

<VirtualHost *:80>
ServerName foo1.com

WSGIScriptAlias / /foo/bar/app.wsgi


</VirtualHost>
<VirtualHost *:80>
ServerName foo2.com

WSGIScriptAlias / /foo/bar/app.wsgi
</VirtualHost>

I used '/' with WSGIScriptAlias as you asked for case where mounted at
root of site.

BTW, if the whole VirtualHost goes through to this application and
nothing else is served by them, and every virtual host on server
follows this same recipe, you could do away with the VirtualHost
directives altogether and just put WSGIScriptAlias at global scope.


Graham

Ksenia

unread,
Feb 8, 2010, 8:37:17 AM2/8/10
to modwsgi

On Feb 7, 11:37 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:


Thank you for answering. In our situation not all VirtualHost that are
hosted on the server are using the same application. So I guess
WSGIScriptAlias should go inside every VIrtualHost.
On another server we are using mod_wsgi for a different setup (one
virtualhost, one app), with the startup script that looks like:

#!/usr/bin/env python
import os
from paste.deploy import loadapp
from pkg_resources import resource_filename
app_path = os.path.dirname(resource_filename('myapp', ''))
if '/test/' in app_path:
config_file = 'test.ini'
else:
config_file = 'live.ini'
config_path = os.path.join(app_path, config_file)
application = loadapp('config:' + config_path)


But I think if I use this script in the situation with 300
VirtualHost, the same application will be loaded 300 times?! Is it how
it supposed to work?

Thanks again,
Ksenia

Graham Dumpleton

unread,
Feb 8, 2010, 11:52:43 PM2/8/10
to mod...@googlegroups.com

So long as you have outside of VirtualHost:

WSGIDaemonProcess Primary threads=15 python-path=/foo/bar/Python

to define the daemon process group. And then:

WSGIScriptAlias / /some/path/app.wsgi

WSGIProcessGroup Primary
WSGIApplicationGroup %{GLOBAL}

inside all VirtualHost's which need it, since not all should be
delegated you are now saying, then there will be only once instance of
application loaded.

This is because WSGIProcessGroup says handle any WSGI applications in
this context in that named process group.

The WSGIApplicationGroup says for the target process, handle any WSGI
applications in this context in the same Python interpreter within
that process.

Thus, so long as all WSGIScriptAlias's refer to the exact same script
file, every virtual host will use that same file and it will only be
loaded once.

Graham

Reply all
Reply to author
Forward
0 new messages