nginx/uwsgi/fastcgi/zomg - too confusing...

283 views
Skip to first unread message

Shannon Cruey

unread,
Jun 1, 2012, 2:17:42 PM6/1/12
to we...@googlegroups.com
OK, now this is just getting weird.  Has anyone set up their web.py application using wsgi on nginx?  I havent even started trying yet because I just don't understand.

As far as I can tell, nginx is pretty easy.  I have it up and running, giving me it's home page.

Here's where it gets confusing... the evidently many meanings of "uwsgi".
  1. nginx has a build in module called uwsgi.  http://wiki.nginx.org/HttpUwsgiModule (This page warns that this module is different than the uWSGI server.)
  2. There is a server (apparently stands alone) called uWSGI.http://projects.unbit.it/uwsgi/
  3. a web.py cookbook http://webpy.org/cookbook/mod_wsgi-nginx talks about mod_wsgi in nginx, which apparently isn't a standard module and must be compiled on the target platform (yuck)

There are even more confusing options out there, like using fast-cgi instead, the list goes on...

This is all so very confusing.  Here's what I require, and I'm asking for advice.

  1. This is a production application - the main reason why I'm not using the builtin server.
  2. I've been "encouraged" to use nginx instead of apache, but it's not required.
  3. What is required is a clean, simple and repeatable install process.  (these environments are in the cloud, so they will be stood up and torn down often.  I really can't afford messing around with having to compile, install stuff that isn't easily done with apt-get, etc. The install process on a vanilla ubuntu server must be do-able with a single script, and (yes I'm about to say it) ... be foolproof.)  Some things in life "just work."  Installing this must "just work."


So, in everyones opinion ... what's the best, clean and simple way to take my web.py application and serve it with a rock solid web server?


Anand Chitipothu

unread,
Jun 1, 2012, 2:39:26 PM6/1/12
to we...@googlegroups.com
uwsgi is swiss-army-knife of web apps. It can work in so many different ways. One easiest way get started is running it as a http server and expose it via nginx using mod_proxy. (This may not be the best approach, but surely the easiest to get started.)

# python code, say hello.py
import web
        
urls = (
    '/', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self):
        return 'Hello, world!\n'


# uwsgi expects a variable with name `application`
application = app.wsgifunc()

if __name__ == "__main__":
    app.run()

Now run uwsgi server.

$ uwsgi -H ~/pyenvs/sandbox --http 127.0.0.1:8080  --wsgi hello -p4

I'm using a virtualenv here and I've specified that with -H option. (if you are not using virtualenv, I strongly recommend you to use it).

--wsgi option specified the wsgi module name, -p4 indicates that we want to run 4 workers. 

--http indicates that we want to run uwsgi as a http server.

Now you can configure nginx to proxy this server.

If you want to run uwsgi as fastcgi-server, use --fastcgi-socket instead of --http. 

If you've nginx server is configured with uwsgi support, then you can specify --socket to make it speak its default custom protocol.

Anand

Jason Macgowan

unread,
Jun 1, 2012, 3:51:17 PM6/1/12
to we...@googlegroups.com
I use web.py with apache2/mod_wsgi for a dozen or so intranet sites each with ~500 requests per day with no issues whatsoever for over 2 years.  Sure 500 requests isn't an extreme load, but it works for me.  It's extremely simple to set-up, and Google is bursting with usage examples.  I know the word is around to stay away from apache for reasons x,y, and z, but it's worked fine for me for what I need it for.


You can send me an email if you need help with specifics on using apache.
Reply all
Reply to author
Forward
0 new messages