When comparing Jetty vs Nginx, the Slant community recommends Nginx for most people. In the question“What are the best cross-platform lightweight HTTP servers?” Nginx is ranked 1st while Jetty is ranked 4th.
Ranked in these QuestionsQuestion Ranking
Because Jetty is built by an assembly of simple components it is very easy to work with. Where possible, features are added by aggregation of components rather than creation of complex deep/optional APIs
Assembly and configuration can be done by the java API, the jetty XML configuration file, which is an IOC style mapping of XML to POJO APIs, other IOC/component frameworks such as Spring and Plexus, OSGi activators, and other XML to POJO mappings such as XBeans
All APIs are public which has resulted in all of the Jetty code being very well maintained and easily understood.
Pro Embedded mode
A Jetty instance can be spawned entirely from Java code (without an external installation or config files), making it a very handy companion for unit/integration tests, conditional/temporary server spawning, and the like.
Jetty was not designed to be an application server, rather it was built from the ground up to be a collection of components that provide HTTP and servlet services. This results in Jetty being very flexible as well as the following benefits:
- Very simple to extend and/or replace components with customized behavior.
- The integration of Jetty into development tools like maven can be very flexible as the components that control the layout of a webapp can be updated to run an unassembled application from source rather than an assembled WAR.
- Very easy to remove features that are not being used to save on memory and CPU costs.
Due to this flexibility Jetty can be used in the following use cases:
- A stand-alone traditional web server for static and dynamic content
- A dynamic content server behind a dedicated HTTP server such as Apache using mod_proxy or mod_jk
- An embedded component within a java application
- As a component to build an application server or Java EE server
For a full list of software powered by Jetty go here.
Pro Highly efficient memory use
Pro Fast and built for scalability
Nginx is event-driven, asynchronous, non-blocking and single threaded (one master process + worker processes). This allows nginx to be manage resources more efficiently compared to thread-based models (like Apache).
Nginx offers a more basic set of functions out of the box compared most web servers. Extra functionality can be added via modules.
Pro Highly efficient CPU use
Pro Free and open source
Pro Advanced load balancing and caching
Pro Event Based Request Handling
Does not fork/thread per request.
Pro Easily configurable
Configuration files are concise and simple.