Simple talk about Apache and Nginx_linux

Source: Internet
Author: User
Tags domain name server nginx reverse proxy

A comparison of the advantages of Apache and Nginx

I've been told that Nginx is better than Apache, faster than Apache, and so on. Nginx is primarily used as a reverse proxy rather than a Web server. I translated a technical book on the reverse agent, at the same time proficient in the development of Apache API, Nginx and Apache working principles are a little understanding, rough talk about the views.

Whether it's nginx or squid, the reverse proxy, its network mode is event-driven. Event-driven is actually a very old technology, as was the case with earlier select and poll. Later, more advanced event mechanisms based on kernel notifications, such as the Epoll in Libevent, enable event-driven performance to improve. The nature of event-driven is IO events, where applications quickly switch between multiple IO handles to achieve so-called asynchronous IO. Event-driven servers, the best thing to do is this IO-intensive work, such as a reverse proxy, which acts as a data relay between the client and the Web server, purely IO operations, and does not involve complex computations. Reverse proxy with event-driven to do, obviously better, a work process can run, no process, thread management overhead, CPU, memory consumption is small.

So nginx and squid do the same. Of course, Nginx can also be a multi-process + event-driven model, several processes run libevent, do not need Apache as frequently as hundreds of of the number of processes. Nginx also works well with static files because the static file itself is also a disk IO operation, as is the process. As for the number of concurrent connections, this is meaningless. I write a Web program that can handle tens of thousands of of concurrency, but if most clients are blocked there, it's not worth it.

Then look at the Apache or resin application servers, called them as application server, because they really want to run specific business applications, such as scientific computing, graphic images, database reading and writing. They are likely to be CPU-intensive services, and event-driven is not appropriate. For example, a calculation takes 2 seconds, and the 2 seconds are completely blocked, and no event is useless. Consider how MySQL would be if changed to event-driven, and a large join or sort would block all clients. At this time, multiple processes or threads to show the advantages of each process to do each of the things, not blocking and interference. Of course, modern CPUs are getting faster, and a single calculation block may be small, but event programming has no advantage as long as there is a blockage. So technology, such as process and thread, does not disappear, but is complementary to the event mechanism and exists for a long time.

To sum up, event-driven is suitable for IO-intensive services, where multiple processes or threads are suitable for CPU-intensive services, each with its own advantages, and there is no inclination to replace who. Then the blind words of the nginx can replace the Apache, it should be a good reflection.

Second, Nginx

Based on Nginx Tomcat load balancing and cluster (super Simple) Focus simple configuration, the disadvantage of many people access, session
Avoid session replication using Nginx cluster policy back-up mode
To open the Nginx gzip compression features detailed
Nginx reverse proxy, load balancing, page caching, URL rewriting and read-write separation

1 The concept of forward agent

The forward agent, the legendary agent, he works like a springboard, simply said, I am a user, I can not access a website, but I have access to a proxy server, this proxy server, he can access that I can not access the site, so I first connected to the proxy server, Tell him I need the content that can't access the website, proxy server to fetch back, and then the branch to me. From the point of view of the website, only when the proxy server to pick up the content of a record, sometimes do not know is the user's request, also hides the user's data, depending on the agent told the website.
The conclusion is that the forward proxy is a server located between the client and server (Origin server), in order to get content from the original server, the client sends a request to the broker and targets (the original server), and the agent then forwards the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward proxy.

2 concept of the reverse agent
For example, user access to Http://www.test.com/readme, but www.test.com does not exist on the Readme page, he was secretly retrieved from another server, and then as their content to return users, but the user does not know. The www.test.com mentioned here has the reverse proxy function set by the corresponding amount of the domain name server.
The conclusion is that the reverse proxy is just the opposite, and for the client it is like the original server, and the client does not need to make any special settings. The client sends a normal request to the contents of the reverse proxy's namespace (name-space), and then the reverse proxy determines where (the original server) forwards the request and returns the obtained content to the client, as if the contents were its own.

3 The difference between the two
From the use to say:
The typical use of forward proxies is to provide access to the Internet for LAN clients within the firewall. The forward proxy can also use caching features to reduce network usage.
A typical use of a reverse proxy is to provide the proxy server behind the firewall to Internet user access. The reverse proxy can also provide load balancing for multiple servers on the back end, or provide buffering services for slower servers on the back end. In addition, the reverse proxy can also enable advanced URL policy and management technology, from which Web pages that are located in different Web server systems exist simultaneously in the same URL space.
From a security standpoint:
The forward agent allows the client to access any Web site and hide the customer itself, so you must take security measures to ensure that only authorized clients are serviced.
The reverse proxy is transparent to the outside, and the visitor does not self access is an agent.

5. See a book on Nginx development "deep understanding Nginx: module Development and Architecture Analysis"

Alibaba senior Nginx Expert writing, thorough analysis nginx architecture, detailed nginx module development methods and techniques. Know not for me, but very worship.

Another book that has been paying attention to is always out of stock called "Web protocol and Practice" O (╯-╰) o

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.