uWSGI as a PSGI server (uWSGI 0.9.7-dev)
PSGI is the equivalent of WSGI in the perl world:
http://github.com/miyagawa/psgi-specs/blob/master/PSGI.pod
The PSGI plugin is officially supported and has an officially assigned uwsgi-modifier: the 5 one
So the first thing to do is to modify your webserver handler to set the modifier1 value to 5:
location / {
uwsgi_pass 192.168.173.5:3031;
include uwsgi_params;
uwsgi_modifier1 5;
}
compiling the PSGI plugin
You can build a PSGI only uWSGI server using the supplied buildconf/psgi.ini file
python uwsgiconfig --build psgi
or compile it as a plugin
python uwsgiconfig --plugin plugins/psgi
if you have not used the default configuration to build the uWSGI core, you have to pass the configuration name:
python uwsgiconfig --plugin plugins/psgi core
will build the plugin using the 'buildconf/core.ini' configuration
There is only an option exported by the plugin: --psgi
You can simply load applications using
./uwsgi -s :3031 -M -p 4 --psgi myapp.psgi -m
or (if you use it as a plugin)
./uwsgi --plugins psgi -s :3031 -M -p 4 --psgi myapp.psgi -m
Tested PSGI frameworks/app
The following frameworks/app have been tested with uWSGI
Multi-app support
You can load multiple almost-isolated apps in the same process with the --mount option
[uwsgi] mount = app1=foo1.pl mount = app2=foo2.psgi mount = app3=foo3.pl
or using UWSGI_SCRIPT/UWSGI_FILE request variables
server {
server_name example1.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
uwsgi_param UWSGI_APPID app1;
uwsgi_param UWSGI_SCRIPT foo1.pl;
uwsgi_modifier1 5;
}
}
server {
server_name example2.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
uwsgi_param UWSGI_APPID app2;
uwsgi_param UWSGI_SCRIPT foo2.psgi;
uwsgi_modifier1 5;
}
}
server {
server_name example3.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
uwsgi_param UWSGI_APPID app3;
uwsgi_param UWSGI_SCRIPT foo3.pl;
uwsgi_modifier1 5;
}
}
Async support
Async support should work out-of-the-box
Threading support
It is supported on ithreads-enabled perl builds. For each app a new interpreter will be created for each thread. Probably it is not too different from a simple multi-process fork()-based subsystem.
Memory usage
There are currently no-known leaks.
Real world example, HTML::Mason
install HTML::Mason PSGI handler
cpan install HTML::Mason::PSGIHandler
create a directory that will hold your site
mkdir mason
create a mason/index.html file
% my $noun = 'World';
% my $ua = $r->headers_in;
% foreach my $hh (keys %{$ua}) {
<% $hh %><br/>
% }
Hello <% $noun %>!<br/>
How are ya?<br/>
Request <% $r->method %> <% $r->uri %><br/>
create the psgi file (mason.psgi)
use HTML::Mason::PSGIHandler;
my $h = HTML::Mason::PSGIHandler->new(
comp_root => "/Users/serena/uwsgi/mason", # required
);
my $handler = sub {
my $env = shift;
$h->handle_psgi($env);
};
pay attention to comp_root, it must be an absolute path !
Now run uWSGI
./uwsgi -s :3031 -M -p 8 --psgi mason.psgi -m
then go to /index.html with your browser
