nginx and Perl: FastCGI vs reverse proxy (PSGI/Starman)
Asked Answered
I

2

24

A very popular choice for running Perl web applications these days seems to be behind a nginx webserver proxying requests to either a FastCGI daemon or a PSGI enabled webserver (e.g. Starman).

There have been lots of question as to why one would do this in general (e.g. Why use nginx with Catalyst/Plack/Starman?) and the answers seem to apply in both cases (e.g. allow nginx to serve static content, easy restart of application server, load balancing, etc.)

However, I am specifically interested in the pros/cons of using FastCGI vs a reverse-proxy approach. It seems that Starman is widely considered to be the fastest and best Perl PSGI application/web server out there, and I am struggling to see any advantages to using FastCGI at all. Both approaches seem to support:

  • UNIX domain sockets aswell as TCP sockets
  • fork/process manager style servers aswell as non-blocking event-based (e.g. AnyEvent) servers.
  • Signal handling/graceful restart
  • PSGI

Similarly, nginx configuration for either option is very similar.

So why you would choose one over the other?

Impeccant answered 23/10, 2010 at 11:20 Comment(0)
Z
18

A reverse proxy setup (e.g. nginx forwarding HTTP requests to Starman) has the following advantages:

  • things are a bit easier to debug, since you can easily hit directly the backend server;

  • if you need to scale your backend server, you can easily use something like pound/haproxy between the frontend (static-serving) HTTP and your backends (Zope is often deployed like that);

  • it can be a nice sidekick if you are also using some kind of outward-facing, caching, reverse proxy (like Varnish or Squid) since it allows to bypass it very easily.

However, it has the following downsides:

  • the backend server has to figure out the real originating IP, since all it will see is the frontend server address (generally localhost); there is almost an easy way to find out the client IP address in the HTTP headers, but that's something extra to figure out;

  • the backend server does not generally know the orignal "Host:" HTTP header, and therefore, cannot automatically generated an absolute URL to a local resource; Zope addresses this with special URLs to embed the original protocol, host and port in the request to the backend, but it's something you don't have to do with FastCGI/Plack/...;

  • the frontend cannot automatically spawn backend processes, like it could do with FastCGI for instance.

Pick your favourites pros/cons and make your choice, I guess ;-)

Zollie answered 4/3, 2011 at 23:34 Comment(2)
Original client IP address is passed in X-Forwarded-For header and original Host header is passed in X-Forwarded-Host header, so the first two downsides are not important.Flaminius
+1 thanks for the comparison. Since one can run a master process to manage back-end processes and threads, the point 3 is non-issue. You raised an interesting point regarding Zope & the way to know original client IP & Hostname to construct valid URLsChrista
F
1

HTTP is well understood by most system administrators and it's easy to debug. There's almost always some kind of reverse proxy already deployed, so it is a piece of cake to just add another configuration stanza to its configuration in order to bring your application up and running in a few seconds. Never tested the speed differances with both settings but on the other hand i never had any problems in that area, so it can't be that bad.

Folk answered 17/12, 2010 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.