Ref:
http://wiki.jmoiron.net/MigratingFromApacheToNginx
http://turbogears.org/2.0/docs/main/Deployment/modwsgi+virtualenv.html
http://wiki.nginx.org/NginxConfiguration
Req:
Debian os, python2.5, apache2, libapache2-mod-wsgi
Nginx is designed to do best to serve static files and proxying request to it's actual processor, so our deployment will use nginx as a front end, actually act as a web server, also do some load balance job; apache act as a application server role in our deployment, we don't use the mod_wsgi(atually apache-mod_wsgi,not that nginx's patch) in a embeded mode, which code executed in the apache's worker process and cause apache do much work that it shouldn't, daemon mode is like FastCGI and apache proxying task to other worker process, like wsgi handers.
Follow above link2 to install apache/virtualenv, also install TG2RC1(currently), then get a sample app "myapp"
Follow above link2 to do a apache+mod_wsgi deployment for the "myapp", best to deploy to /usr/local/turbogears/ for convenient, make sure it's run ok.
Modify /etc/apache2/ports.conf to add muti-virtualhost refer to our "myapp"
Modify /etc/apache2/sites-available/myapp to follow above ports
#Apache configuration File
#Read README.txt
#1. This file should be added to your apache config folder; On Debian copy to /etc/apache2/sites-available/
#Default location for tg2 project is /usr/local/turbogears/myapp. That is where you should put your project. This folder should be outside of apache location. Your package should not be installed into python site-package.
#Embeded mode (http://example.com/myapp).For big websites with a lot of memory and visitors.
#WSGIScriptAlias /myapp /usr/local/turbogears/myapp/apache/myapp.wsgi
#3. Test if modwsgi is working. Uncomment below line, and go to http://localhost/test:
#WSGIScriptAlias /test /usr/local/turbogears/myapp/apache/test.wsgi
#5. [Optional] Deamon mode with 10 threads and 3 processes. For small to medium website.
#WSGIDaemonProcess myapp threads=10 processes=3
#WSGIProcessGroup myapp
#WSGIScriptAlias / /usr/local/turbogears/myapp/apache/myapp.wsgi
#6. Directory Permission.
Order deny,allow
Allow from all
#7. [Optional] If you want to use Virtualhost apache settings.
#Sample Virtual Host configuration would look like this:
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Test the deployment
$ /etc/init.d/apache2 restart
$ nginx -t -c /etc/nginx/nginx.conf
$ nginx -c /etc/nginx/nginx.conf &
#open browser to browse the http://your_debian_host/ check your deploment
this is very simple config, for the production enviroment, you should check the more doc to get the best suit for you.
We get the perfectly 3-tiers infrastructure for our n-tiers-oriented application, but it compares to the nginx+nginx-mod_wsgi style may has little speed limitation, no benchmark data now, maybe someone can do a test to get the actual performance data.