Home > Back-end >  The difference between Nginx and Apache Tomcat
The difference between Nginx and Apache Tomcat

Time:09-25

Nginx and Apache Tomcat and advantages and disadvantages of the difference between
1, the definition:
1) the Apache
Apache HTTP Server (Apache) is an open source Apache software foundation's web page, it is a modularized Server, you can run on almost all widely used computer platforms, it belongs to the application Server,
Apache support module, more stable performance, the Apache itself is a static analysis, suitable for static HTML, images, etc., but can be extended by the script, and support dynamic pages, such as module,
Disadvantages: relative complex configuration, itself does not support dynamic pages,
Advantages: relative to the Tomcat server processing static files are its advantages, speed, Apache is the static analysis, suitable for static HTML, images, etc.,
(PHPcgiperl Apche can support, but want to use Java, you need to Tomcat in the Apache backend support, will be treated as Java forward requests by the Apache Tomcat,)

2) Tomcat:
Tomcat is the Apache Software Foundation (Apache Software Foundation's Jakarta project of a core project, the Tomcat server is a free open source Web application server, belongs to a lightweight application server,
Tomcat application server (Java), it is just a Servlet (JSP) was translated into a Servlet container, and can be thought of as the expansion of the Apache, but can run independently of the Apache,
Disadvantages: say that Tomcat can only be used as a Java server
Advantages: dynamic analytic container, handle dynamic requests, to compile JSP/Servlet container,

Three port:
8005: close the tomcat communication interface
8009: HTTP server with other communication interface, is used to set the HTTP server
8080: HTTP connection to use, such as a browser to access
3) Nginx
Nginx is Russia people write very lightweight HTTP server, Nginx, its pronunciation is "engine X", is a high-performance HTTP and the reverse proxy server, at the same time is also an IMAP/POP3/SMTP proxy server, its characteristic is occupy less memory, concurrent capability is strong, easy to develop, easy deployment, Nginx generic server support multiple language,
Disadvantages: Nginx is only suitable for static and reverse proxy,
Advantages: load balancing, reverse proxy, static file processing advantages, Nginx static request processing speed is higher than the Apache,
Nginx dynamic separation mechanism, static request can be directly through the Nginx processing, dynamic requests to forward requests to the backend to a Tomcat,

Tomcat in combination with Apache, Nginx high performance of web server


Although Tomcat is a servlet and JSP container, but it is also a lightweight web server, it can deal with dynamic content, can also handle static content, however, the biggest advantage of Tomcat is dynamic request processing, ability to deal with the static content than apache and nginx, and after tests found that Tomcat in high concurrency scenarios, the maximum number of simultaneous connections to accept is limited, the number of connections can lead to Tomcat in the "zombie" state, therefore, in this case, we can use nginx high concurrency, the characteristics of low consumption used with Tomcat, therefore, Tomcat and nginx, there are several reasons as follows: using apache
1, ability is inferior to the Apache tomcat to handle HTML and nginx, tomcat to handle the speed of static content as Apache and nginx,
2, the maximum number of concurrent tomcat accept co., LTD., the number of connections is overmuch, can lead to "zombie" tomcat, lose response in subsequent connection, need to combine nginx,

Usually, tomcat and nginx, combined the Apache, nginx, Apache can provide web services, dynamic request can also be forwarded to the tomcat server, but in a high performance on the site, usually nginx, Apache only provides the function of the agent, the request is forwarded to the tomcat server, and for the response of the static content, is the responsibility of the front-end load balancer to forward to specialized static server for processing, its architecture is similar to the diagram below:


In this architecture, when haproxy or nginx as front-end agent, if it is a static content, such as HTML, CSS, etc, are directly to the static server processing; If the requested content such as images, the images directly to the server; If the request is for dynamic content, to the tomcat server, but on the tomcat server, at the same time running nginx server, at this time of nginx as static server, it does not deal with static request, its role is mainly to accept the request, and forwards the request to the tomcat server, in addition, nginx didn't have any effect,

2, the difference:
The difference between 1) Nginx and tomcat

Nginx do static content service and the proxy Server, commonly used foreign forward requests directly to the back of the Application Server (tomcat, Django, etc.), tomcat more used to make an Application container, let Java web app in the contents, strictly speaking, the Apache HTTP Server, and nginx should be called the tomcat is an Application Server is a Servlet/JSO Application container,
Client via HTTP Server access storage on the Server resources (HTML files, image files, etc.), the HTTP Server is simply put the file on the Server through HTTP protocol to transmit to the client according to the facts,
Application Server is running behind in the HTTP Server, application execution, the dynamic content into static content, through to the client as a HTTP Server to distribute
Note: nginx is distributed the request made, don't do processing!!!

2) the difference between nginx and Apache

Apache is a synchronization process model, a connection is corresponding to a process, and nginx is asynchronous, multiple connections (level) can correspond to a process,
Nginx lightweight, concurrent, handle good static file
Apache overstable, support for PHP is simpler, nginx need to coordinate with other backend to use, handle dynamic requests have an advantage, it is recommended to use the front nginx concurrent, back-end Apache cluster, combination would be better to
Nignx forward agent and reverse proxy

3, the advantages and disadvantages compared

1) nginx advantages relative to the apache
Lightweight, web services, than apache takes up less memory and resource concurrent resistance, nginx process the request is asynchronous non-blocking, and apache is blocking, under the high concurrency nginx can keep low resource consumption of high performance highly modular design, write module is relatively simple to provide load balancing
Community is active, all kinds of high performance module product quickly
2) the apache relative to the advantages of nginx
Apache rewrite (rewrite) than nginx powerful;
Support dynamic pages;
Support module, the basic cover all applications.
Stable performance, and relatively bug nginx is more,
3) both advantages and disadvantages compared
Nginx configuration is concise, Apache complex;
Nginx static processing performance more than 3 times higher than the Apache;
Apache support for PHP is simpler, Nginx need to cooperate with other backend; Apache component than Nginx;
Apache is a synchronization process model, a connection corresponds to a process; Nginx is asynchronous, multiple connections (all levels) can correspond to a process;
Nginx processing good static files, use less memory;
Dynamic request by apache, nginx is only suitable for static and reverse;
Nginx for front-end server, load performance is very good;
Nginx itself is a reverse proxy server, and support load balancing
4)
Nginx advantages: * * * * load balancing, reverse proxy, static file processing advantages, Nginx static request processing speed is higher than the apache;
Apache advantages: * * * * relative to the Tomcat server processing static files are its advantages, speed, Apache is the static analysis, suitable for static HTML, images, etc.,
Tomcat: * * * * dynamic analytic container, handle dynamic request, is compiled JSPServlet container, Nginx dynamic separation mechanism, static request can be directly through the Nginx process, dynamic requests to forward requests to the backend to a Tomcat,
Apache has the advantages in the treatment of the dynamic, Nginx concurrency is better, low CPU memory footprint, if rewrite is frequent, the Apache or suitable for,

CodePudding user response:

  • Related