Home Backend Development PHP Tutorial Introduction to nginx

Introduction to nginx

Aug 08, 2016 am 09:21 AM
apache nginx web

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to build a Zookeeper cluster in CentOS How to build a Zookeeper cluster in CentOS Apr 14, 2025 pm 02:09 PM

Deploying a ZooKeeper cluster on a CentOS system requires the following steps: The environment is ready to install the Java runtime environment: Use the following command to install the Java 8 development kit: sudoyumininstalljava-1.8.0-openjdk-devel Download ZooKeeper: Download the version for CentOS (such as ZooKeeper3.8.x) from the official ApacheZooKeeper website. Use the wget command to download and replace zookeeper-3.8.x with the actual version number: wgethttps://downloads.apache.or

How to solve CentOS system failure How to solve CentOS system failure Apr 14, 2025 pm 01:57 PM

There are many ways to solve CentOS system failures. Here are some common steps and techniques: 1. Check the log file /var/log/messages: system log, which contains various system events. /var/log/secure: Security-related logs, such as SSH login attempts. /var/log/httpd/error_log: If you use the Apache server, there will be an error message here. 2. Use the diagnostic tool dmesg: display the contents of the kernel ring buffer, which helps understand hardware and driver questions

How to start nginx How to start nginx Apr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

See all articles