-2

now bear with me please. I'll explain from the beginning but very briefly. 8 months ago, I worked in a web project with python, that used no framework (from scratch). I limited myself to implement views and templates, but with the pass of the months I became curious so I made some research.

Now I'm checking about WSGI and how to make "do-it-yourself" frameworks. But I'm a bit curious about some things. When I was in that project 8 months ago, we used a web server, but I remember in the web there was a "web server" component too.

The component was Tornado Web Server, and this other server was nginx. Now, what's the difference between one and the other server?

And if the component (Tornado or another one) is not the only thing I need for deployment, what else I need?

Xanathos
  • 598
  • 3
  • 15
  • 31

3 Answers3

2

To clarify:

Tornado is a Python web framework and asynchronous networking library.

That's their own definition, not mine. (https://pypi.python.org/pypi/tornado)

Tornado can function as a web server as well. Some Python web development frameworks don't really function as a web server - they need to be bootstrapped onto another library for development work. Others can function as a web server, but don't recommend it - they were designed to write code, not build it.

If you're inclined to do so, you can serve everything from Tornado directly. Most people - including the Tornado development team - have seen much better performance by putting Tornado behind nginx , and using nginx to load-balance and serve static content. http://www.tornadoweb.org/en/stable/overview.html?highlight=nginx

There are many different ways to deploy WSGI applications to the internet. Some of them include:

  • Directly deploy the app on port80
  • Use nginx/apache as a public load-balancer:
    • proxy connections to the app running on a local port
    • run the app under uwsgi, configure the public load-balancer to proxy requests to uwsgi

There are also other ways to deploy WSGI apps using gunicorn, eventlet, twisted, and countless other networking or web serving libraries.

To answer your question :

In the project you worked on, nginx functioned as a public facing web server. Tornado (most likely) functioned as both a web framework and a private web server.

Jonathan Vanasco
  • 15,111
  • 10
  • 48
  • 72
  • Yes, in the project I mentioned, they used tornado as a component of the web, and used nginx to deploy it. On code, I used tornado's request and response properties basically, although I think other apps inside the web, used some other functionalities. Thanks for the feedback. Made clear a lot of things =) – Xanathos May 08 '13 at 19:26
1

Xanathos, the component you mentioned Tornado is a web server for dealing with an extremely large amount of simultaneous connections. It is built on Twisted Python, and I would not recommend using it if you are still a beginner. I might suggest that you look into Python Werkzeug as it will give you a good introduction to WSGI.

Edit: If you want something that is a very light framework you may also be interested in Flask

Matthew Graves
  • 3,226
  • 1
  • 17
  • 20
  • Yes, I consider myself a beginner, but I prefer to learn from scratch. I heard of Flask before, thank you for the advice. Do you know a resource which explains about servers for WSGI and how to use them for deployment? – Xanathos May 08 '13 at 18:50
  • Werkzeug is a WSGI server. Why not start here: http://werkzeug.pocoo.org/docs/ – Matthew Graves May 08 '13 at 18:53
  • Ok, I'll experiment a bit on that. Thanks =) – Xanathos May 08 '13 at 19:22
1

Tornado is a web server for use by Python web applications.

nginx is a more generic web server that you use typically as a front in front of other webservers to do virtual hosting or other proxying. It competes primarily with Apache.

So they are both web servers, but the do completely different things.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • Tornado can act as a web server, but it's really an application framework / networking library. It's largely used to write web apps, but you could write virtually any server with it ( MTA , IRC, Telnet, etc ) You can also run/mount WSGI webapps on Tornado, but it's not really recommended - you don't get the performance gains that a native tornado app would get ( http://stackoverflow.com/questions/9942188/running-a-pyramid-wsgi-application-under-tornado ). Most people I know deploy WSGI apps with other servers. – Jonathan Vanasco May 08 '13 at 19:46