6 ms·
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 laye
by pifflesnort 14y ago
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?
- nacs 14y agonginx 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 http://wiki.nginx.org/Modules).
- benhoyt 14y agoIt'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.
- aleem 14y agoI'm curious to know - did you consider Varnish? It's much faster as a rev proxy caching server.
- papsosouid 14y agoNo, it isn't. It claims to be faster than squid, not nginx. But it doesn't even meet that claim.
- CrLf 14y agoProxy 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.
- IvarTJ 14y agoFor my hobby programming server, I primarily use it to serve different web applications on different domains. The server is a proxy to web applications that listen on different ports on the server. This allows me to multiplex different web servers and relieves me of finding modules that glue together nginx and various programming languages.
- jdub 14y agoGet a cheap load balancer that can make better decisions because it's operating at the HTTP layer... oh, nginx! :-)
- icebraining 14y agoAn HTTP level load balancer like nginx can do session affinity, which is helpful when your application server isn't stateless. I guess a TCP load balancer could do them based on IP as well, but IPs don't identify sessions as well as cookies can.
- AaronBBrown 14y agoAs can haproxy or any other L7 load balancer.
- icebraining 14y agoSure, but those aren't TCP load balancers (at least, not if you enabled that functionality), since they work at the HTTP level. I wasn't claiming nginx was the only way to do session affinity, just that it's a reason to use it over a TCP load balancer.
- mortehu 14y agoI think one response that's missing here is that application servers might use a lot of RAM while they're running, so you can only afford to have a few instances running. In such cases, it's better to have nginx buffer the response and deal with the slow clients, than holding up an application server for the duration of the transfer.
- baudehlo 14y agoAnother reason people haven't considered here is that nginx can display error pages for you when your application server crashes, or is taking too long to serve requests. This is much nicer for the user than a browser error.