Live data from Hacker News

Why Use Nginx?

wiki.nginx.org

11–20 of 91 posts

Re: Why Use Nginx?

#11
post #8

A big gotcha with nginx is if you have an app server behind it and you foolishly have a long running web request which runs longer than the proxy timeout, nginx will retry the original web request. Better make sure everything is idempotent and don't have long running web processes. It is bad design, but we ran into this. Code that used to run in a few seconds started taking longer and then ran infinitely long without…

Oh really, does it do it for POSTs? It should retry for GET, but not POSTs (which is exactly why there is a difference).

If you have non-idempotent GETs in your app, then that's the app's fault. If Nginx is retrying POSTs then it's Nginx's fault.

Re: Why Use Nginx?

#12
I dropped Apache in favor of Nginx about two years ago. Haven't looked back since then. It's so much easier to configure and it uses far less memory.

Re: Why Use Nginx?

#13
Nginx is great, but before you get down and start using it, make certain that you'll never, ever use any features it doesn't support. I was bitten by this when I found out Nginx has no equivalent to Apache's mpm_itk_module.

Re: Why Use Nginx?

#14

Nginx is great, but before you get down and start using it, make certain that you'll never, ever use any features it doesn't support. I was bitten by this when I found out Nginx has no equivalent to Apache's mpm_itk_module.

What does that mod do out of curiosity?

Re: Why Use Nginx?

#15

Nginx is great, but before you get down and start using it, make certain that you'll never, ever use any features it doesn't support. I was bitten by this when I found out Nginx has no equivalent to Apache's mpm_itk_module.

What does that mod do out of curiosity?

"mpm-itk allows you to run each of your vhost under a separate uid and gid—in short, the scripts and configuration files for one vhost no longer have to be readable for all the other vhosts"

- http://mpm-itk.sesse.net/

Re: Why Use Nginx?

#16
One thing I still don't understand is why one would use a proxy server at all?

Why not just have your load balancers (which can operate cheaply at the TCP layer) throw traffic directly at your application servers?

If you need caching, that's cheap to do, too. If you need static file serving, can't you another load balancer end-point that points directly at static content servers, or make your application servers faster?

Is nginx primarily useful for slow application server runtimes that can't keep up with what nginx can do?

Re: Why Use Nginx?

#17

One thing I still don't understand is why one would use a proxy server at all? Why not just have your load balancers (which can operate cheaply at the TCP layer) throw traffic directly at your application servers? If you need caching, that's cheap to do, too. If you need static file serving, can't you another load balancer end-point that points directly at static content servers, or make your application servers fast…

nginx can do a ton of things with modules. One of the reasons I use it is because I can pattern match incoming URLs and send them to different servers based on some pretty fancy rules routing rules.

Also, there are many that use nginx as the load balancer (including me). Would a TCP load balancer be better? Possibly but it also comes at an additional cost whereas nginx is free and far more flexible with routing HTTP content.

I'm not even going to summarize all the other things nginx can do via modules (Lua, memcached, etc -- http://wiki.nginx.org/Modules).

Re: Why Use Nginx?

#18

One thing I still don't understand is why one would use a proxy server at all? Why not just have your load balancers (which can operate cheaply at the TCP layer) throw traffic directly at your application servers? If you need caching, that's cheap to do, too. If you need static file serving, can't you another load balancer end-point that points directly at static content servers, or make your application servers fast…

It's a good question. We (a large-scale website serving 250,000 pages/day) use Python+CherryPy for our "application server", but that's sitting behind an nginx reverse proxy.

The main reason is that nginx is much better and faster at handling certain things than Python:

* handling HTTPS and serving plain old HTTP to the application server so Python doesn't have to worry about it

* doing the gzipping of content before it goes out

* routing requests to different places/ports based on various elements matched in the URL or HTTP headers

* virtual hosts, i.e., "Host" header matching and routing things to the right place based on that

* various request sanitization, like setting client_max_body_size, ignore_invalid_headers, timeouts, etc.

Historically we've also had multiple types of application servers, some Python and some C++, and nginx routes requests to the right app server (based mainly on URL prefix).

We also use nginx to do GeoIP with the GeoIP nginx module (though arguably that would be just as simple in Python).

Edit: Note that we don't use it because our "application server is slow" (it's not). Also, I know some people use nginx to serve static content, because it's usually much faster/better than say Python at doing that -- we serve static content via Amazon S3 and a CDN, so that's a non-issue for us.

Re: Why Use Nginx?

#19
post #4

One major drawback is you can't control output buffering and gzip with phpfpm (LAMP stack equivalent) You cannot flush head, the user has to wait until the whole page loads before rendering.

Latest version got much better at handling streams if I remember correctly

True. Correct me if I am wrong but I am not sure if streams work for general text pages (like blogs, eCommerce, etc). It is better suited for chat-style applications (comet).

Re: Why Use Nginx?

#20

One thing I still don't understand is why one would use a proxy server at all? Why not just have your load balancers (which can operate cheaply at the TCP layer) throw traffic directly at your application servers? If you need caching, that's cheap to do, too. If you need static file serving, can't you another load balancer end-point that points directly at static content servers, or make your application servers fast…

Proxy servers aren't just useful for load balancing. I'd say that this isn't the average use case for Internet-facing HTTP reverse proxies at all (people get all worked up by the big boys, but that's not what most Internet applications are about).

In most cases reverse proxies are useful as application firewalls, where you control what passes and what doesn't in an application-independent way (i.e. your systems administrators can do this without the need to touch applications - which in many enterprise settings can't be easily touched by developers, much less by operations).

This is why I have yet to use nginx, and stay with good-old apache. Apache is extremely configurable (not only is mod_rewrite very powerful, but you can insert your own request mangling scripts for that weird edge case).

Apache is also good enough for most cases. For applications with a few thousand users hanging on the site all day, apache can handle it just fine in a 5-year old, low-end Celeron rack server, with just 5% CPU usage even with all connections being SSL for both Internet and application server traffic.

Caching and load-balancing are nice things to have, but not the reason for having a reverse proxy in most cases.

Post reply on HN