Distinguishing between nginx and thin
Asked Answered
R

3

13

This is a newbie question around nginx and thin in the rails environment. In reading/learning on rails I frequently hear about nginx and thin being a great combination for a rails site. In reading the descriptions of each, they both describe themselves as web servers, so I'm a little confused at what the combination brings to the table. If anyone could briefly describe what they are and how they complement each other I would be greatly appreciative.

Thanks!

Rosenfeld answered 9/9, 2010 at 14:48 Comment(0)
H
25

A typical small application deployment will have Nginx(or Apache) and a handful of Thin(or Mongrel, Unicorn, etc) servers running all on one machine.

Nginx receives every request. It then serves and static files directly (css, js, images, cached stuff). If the request requires processing it then hands the request off to a rails process (Thin).

This way your (relatively) slow application servers are freed up from serving static files, and your web server is providing a sort of load balancing.

The benefit of Nginx/Thin over something like Apache/Mongrel is that Nginx/Thin can communicate directly via a unix socket, removing the overhead of communicating via the tcp/ip stack.

Halliburton answered 9/9, 2010 at 15:53 Comment(1)
To more directly answer the question: Nginx is a web server. It serves static files and routes non static request to your application servers. Thin is an application server, it actually processes requests with your Rails/Rack application.Halliburton
C
4

Thin is an application server while Nginx is a web server.

From http://www.javaworld.com/javaqa/2002-08/01-qa-0823-appvswebserver.html

The application server exposes business logic to client applications through various protocols, possibly including HTTP. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application program can use this logic just as it would call a method on an object (or a function in the procedural world).

Cara answered 11/6, 2012 at 7:8 Comment(0)
M
2

Speaking out of ignorance (I've never used Thin), it is quite normal to mix nginx and an application server together, using nginx to serve up static content and act as a reverse proxy for the application server.

This makes it easy to blend ludicrously fast static content serving with the application server of choice (which varies between programming languages), all coming from the same address:port.

Melodrama answered 9/9, 2010 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.