Function comparison of Tomcat and Nginx

Tomcat functional responsibilities:

Tomcat runs on JVM. Like the HTTP server, it binds IP addresses and listens on TCP ports. It also includes the following responsibilities:

  • Manage the life cycle of Servlet programs
  • Map the URL to the specified Servlet for processing
  • Cooperate with Servlet program to process HTTP requests - generated based on HTTP requests

The HttpServletResponse object is passed to the Servlet for processing, and the content generated by the HttpServletResponse object in the Servlet is returned to the browser.

Nginx functional responsibilities:

Although Tomcat can also be considered an HTTP server, it is usually still used with Nginx:

  • Separation of dynamic and static resources - use Nginx's reverse proxy function to distribute requests: all dynamic resource requests are handed over to Tomcat, while static resource requests (such as pictures, videos, CSS, JavaScript files, etc.) are directly returned to the browser by Nginx , This can greatly reduce the pressure on Tomcat.
  • Load balancing. When business pressure increases, one Tomcat instance may not be enough to handle it. At this time, multiple Tomcat instances can be started for horizontal expansion, and Nginx's load balancing function can distribute requests to different instances through algorithms. deal with

The difference between the two:

Apache/nginx is called Http Server; and tomcat is an Application Server, or a servlet/jsp application container (python cannot run directly on tomcat, java can)
An HTTP Server is concerned with transmission and access control at the HTTP protocol level, so on Apache/Nginx you can see functions such as proxy and load balancing. The client accesses resources stored on the server (HTML files, image files, etc.) through HTTP Server. Through CGI technology, the processed content can also be distributed through HTTP Server, but an HTTP Server always only faithfully transmits the files on the server to the client through HTTP protocol. (CGI technology: Public Gateway Interface is a standard interface for external extension applications to interact with the Web server. There are many common ways for the server to interact with the client, and CGI technology is one of them.
(1) The Web client's browser decodes the first part of the URL and connects it to the Web server.
(2) The Web browser provides the remaining parts of the URL to the server.
(3) The Web server converts the URL into a path and file name.
(4) The Web server sends HTML and other files that make up the requested page to the client. Once the page content is transmitted,
This connection is automatically disconnected.
(5) On the client side, the HTML script prompts the user to perform actions or input. When the user responds, the client requests the Web server to establish A new connection.
(6) The Web server transmits this information and other process variables to the CGI program specified by HTML in the form of a URL.
(7 ) CGI responds according to the input and transmits the response result to the Web server.
(8) The Web server transmits the response data to the client and closes the connection after completion.

The application server is a container for application execution. It first needs to support the runtime of the development language (for Tomcat, it is Java) to ensure that the application can run normally on the application server. Secondly, it needs to support application-related specifications, such as class libraries and security features. For Tomcat, it is necessary to provide standard class libraries, Interfaces, etc. required for JSP/Sevlet operation. For convenience, application servers often integrate HTTP Server functions, but they are not as powerful as professional HTTP Servers. Therefore, application servers often run behind HTTP Servers, execute applications, and convert dynamic content into static content through HTTP Server distributes to clients.

Guess you like

Origin blog.csdn.net/weixin_44816664/article/details/135008987