Home > Backend Development > PHP Tutorial > Introduction to nginx

Introduction to nginx

WBOY
Release: 2016-08-08 09:21:23
Original
1116 people have browsed it

Nginx (pronounced as "engine x") is a software developed by Russian software engineer Igor An open source web server written by Sysoev. Since its release in 2004nginx has been focusing on high performance, high concurrency, and low memory usage, and also has some unique Webserver functions, such as load balancing and caching , access and bandwidth control and the ability to effectively integrate with various applications make nginx a good choice for modern website architecture. Currently, nginx ranks second on the list of the most popular webserver software on the Internet.

1. Why is high concurrency so important?

The Internet is so popular and ubiquitous now, and we know that this was hard to imagine 10 years ago. Moreover, since clickable text is generated from simple HTML based on NCAS (Translator’s Note: National Center for Supercomputer Applications) to Apache based The major evolution of web services has made the Internet a common communication medium for 2 billion netizens around the world. The ever-expanding proliferation of computers, mobile devices and, most recently, tablets has resulted in very rapid changes in the Internet space and the wired digitization of the entire economy. Online services have also become more detailed with the real-time and effective life and entertainment information. And there have been significant changes in the security aspects of online business. As a result, websites have become more complex than before, requiring more engineering work to make the Internet more robust and scalable.

The biggest challenge for a website architecture is concurrency. From the very beginning of the Network service, concurrency levels have continued to grow. It is not uncommon for a website to serve hundreds, thousands or even millions of users at the same time. Ten years ago, the cause of concurrency was slow clients - back then users used ADSL or dial-up to connect; Now , concurrency is driven by mobile clients and some need to persist through A combination of updated application architecture that connects to update news, tweets, friend messages, and more. Another factor that causes increased concurrency is that modern browsers open 4 to 6 connections for a website at the same time to load web pages to increase page loading speed.

To illustrate the problem when the client is slow, suppose there is a simple web service based on apache that can generate a response text or image of 100k size, then this service It only takes a fraction of a second to generate or query this page, but in a client with 80kbps (10kB/s)bandwidth it takes 10 seconds to send this request; Originally, this web service could quickly pull 100k content, but it took 10 seconds to transmit the 100k content before the connection could be released. Now we assume that there are 1000 concurrently connected clients requesting similar content. If a client is allocated 1M of additional memory, then in order to satisfy these 1000clients A request of 100K requires 1000M (approximately 1G) additional memory. In fact, a standard web service based on apache usually allocates more than 1M memory for each connection, and sadly the effective rate of mobile communication is only tens of kpbs. Although the problem of sending content to slower clients may be alleviated to a certain extent through the socket buffering of the operating system kernel, it is not a universal solution and may have unexpected negative effects.

The handling of persistent connections makes concurrency issues more prominent. This is because to avoid the delay caused by re-creating the httpconnection, the client must always remain connected to the webserver Moreover, the web service also allocates additional memory space for each connection.

Therefore, in order to be and be able to continuously handle the increasing load caused by the increasing number of users and obtain higher concurrency, a website must be built based on a series of very high-performance modules. However, other parts such as hardware(CPU,memory,hard disk), network capacity, application and data storage architecture are obviously equally important, which determines the web server The number of client connections accepted and handled. So the web server needs to be able to meet the growing number of concurrent connections and requests per second through non-linear scaling. Is

Apache suitable?

Apache, originated in the early 1990s, is still the dominant web server software on the Internet. Starting in 2000, it became obvious that stand-alone web services could not be easily replicated to meet the growing number of network services. Although Apache provides a solid foundation for future development, its architecture of making a copy of itself for each new connection cannot meet the requirements of a website's non-linear expansion. Ultimately, Apache became a fully functional web server with a range of third-party plug-ins and almost universally applicable to any type of secondary development website. But it doesn't do you any good to be that heavy, and the downside is that combining so many features and tools into one software also increases the cost of each connection. CPU and memory usage thus reduce the scalability of the software.

Therefore, since server hardware, operating system, and network resources are no longer the main factors limiting website growth, developers around the world have also begun to seek more effective ways to run web servers. About ten years ago, Daniel, a famous software engineer Kegel claimed that "it's time for web servers to have only tens of thousands of concurrent requests" and predicted what we now call Internet cloud services. Kegel's C10K list also included some attempts to solve the problem of the number of concurrent connections under the best conditions of the web server, and ultimately proved that nginx is the most effective solution.

In order to solve the problem of 10,000 simultaneous connections on the C10K list, nginx considered a different architecture - an architecture that is more suitable for non-linear expansion in both the number of concurrent connections and the number of requests per second. Since nginx is based on an event model, it does not follow Apache's rules of duplicating each new process or creating a separate thread for each page. As a result, even if the load increases, memory and CPU usage remain controllable, which allows nginx to handle tens of thousands of concurrent requests on a single server with ordinary hardware.

nginx The first version was released to offload concurrency and timeout processing through nginx for static content deployed under apache in apache-based application servers, such as html, css, javascript scripts and images. During its development, nginx has integrated with third-party applications by using FastCGI, uswgi or SCGI protocols, and has distributed object caching systems like memcache. At the same time, some useful features have been added, such as reverse proxy with load balancing mechanism and caching. These additional features make nginx an effective combination of tools for building a scalable web-based infrastructure.

Are there more advantages when using nginx?

Usually efficient and high-performance processing of large concurrent requests is the main advantage of nginx. At the same time, using nginx has some other benefits.

Over the past few years, network architects have embraced the idea of ​​loose coupling and begun to separate the underlying components of applications from web services. However, previously existing websites based on LAMP (Linux, Apache, MYSQL, PHP, Python or Perl) may now include websites based not only on LEMP (E pronounced "engine x") but are becoming more and more common in practice. Web servers need to be pushed to the edge of the infrastructure or the same or some new applications and data tools need to be integrated in different ways.

nginx is very suitable for the above situation. This is because nginx provides some major functions from the application layer to the more efficient edge server (Translator's Note: Unfamiliar readers can query the edge server) layer, such as offloading concurrency, Timeout handling, SSL (Secure Socket Layer), content staticization, compression and caching, connection and request throttling and even HTTP streaming. At the same time, nginx can also directly integrate with memcached, Redis and other NoSQL solutions to improve performance under large concurrent users.

With the popularity of the latest open tool components and programming languages, more and more companies are beginning to change their habits of developing and deploying applications. And nginx has become a model of this type of change, developing into one of the most important components. At the same time, it has also helped many companies achieve sustained and rapid development of web services within budget.

The first line of code for nginx was written in 2002, and by 2004 nginx was released under the 2-two-clause BSD license. Since nginx was released, its user base has continued to grow and has been of great help to the entire community by contributing ideas, submitting bugs, and making various comments and suggestions.

nginx’s code base is original and entirely implemented in C language. It has also been ported to operating systems on a variety of architectures, such as Linux, FreeBSD, Solaris, Mac OS X, AIX and Windows systems. nginx also has its own libraries, and these libraries do not use C libraries that do not exist in the system. Therefore, in addition to zlib, PCRE and OpenSSL, users can remove libraries that they do not need or may have license conflicts.

Let’s talk a little bit about the windows version of nginx. nginx running under windows is more of a proof of concept than a fully functional port. Nginx also has limitations under Windows, that is, nginx is not well compatible with the Windows kernel. Already known problems with lower versions of nginx in Windows include less concurrent support, low performance, cache failure, and bandwidth policy failure. In the future, the Windows version of nginx will be more consistent with mainstream functions.

The above is an introduction to nginx, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template