In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the function and configuration method of Nginx". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the function and configuration method of Nginx".
This article mainly briefly introduces the relevant knowledge of Nginx, including the following parts:
What scenarios does Nginx apply to?
Why is there Nginx?
Advantages of Nginx
Compilation and configuration of Nginx
What scenarios does Nginx apply to?
As shown in the figure, a request first goes through Nginx to the application service layer, and then accesses the data layer (such as Redis, MySQL, etc.) to provide basic data functions. Because our application service requires that the development efficiency is very high, so its running efficiency is very low, and its qps, tps or concurrency are all limited, so we need to cluster many of these application services to provide highly available services to users. Once many services are clustered, we need Nginx to have reverse proxy function, which can pass dynamic requests to application services.
When application services form a cluster, there are bound to be two requirements:
Dynamic expansion is needed.
We need to do disaster recovery when there is something wrong with some services.
In this way, the reverse proxy must have load balancing function.
Secondly, in such a link, Nginx is an edge node in the intranet. With the growth of the network link, the delay experienced by the user will increase, so it is necessary to cache the dynamic content that the user looks constant or unchanged for a period of time in the Nginx part, and Nginx provides access directly to the user, so the user delay will be greatly reduced. So another function of reverse proxy is caching to reduce the delay of user access.
Like many static resources of css, js and img, it is not necessary to access them through application services, only static resources placed on the local file system are directly accessed by Nginx. This is Nginx's static resource service.
There are many problems with the performance of the application service itself, such as the database service is much better than the application service, because the business scenario is relatively simple, and the concurrent performance and tps are much higher than the application service, so the third application scenario is extended: Nginx directly accesses the database, Redis, and takes advantage of the powerful concurrency performance of Nginx to achieve some complex business functions such as web firewall. This requires api services to have strong business processing capabilities, so JavaScript integrated with OpenResty and Nginx, applying language functions such as JavaScript and lua and some toollibraries that come with their languages to provide complete API services.
Why is there Nginx?
With the rapid popularization of the Internet, as well as the rapid development of globalization and the Internet of things, the amount of data on the Internet is growing rapidly.
The number of CPU cores has grown from single core to 16 core or even 32 core, but because the operating system and a large number of software are not ready to serve the multi-core architecture, the performance of the service is usually not doubled.
Apache's architectural model that a process will only process one link and one request at a time, and then the next request will be processed. It actually has the characteristic of switching between processes using the operating system, because the operating system has only a limited amount of CPU, but the operating system is designed to serve hundreds or even thousands of processes at the same time, while Apache can only serve one link. This mode will cause Apache to have no way to open hundreds of thousands or millions of processes when it has to face hundreds of thousands or millions of links. The cost of inter-process switching is too high. The more concurrent connections, the greater the performance consumption caused by this unnecessary inter-process switching. Nginx is specially created for such application scenarios, and Nginx can handle millions or even tens of millions of concurrent links.
Advantages of Nginx
High concurrency and high performance
As long as we use enough memory for each link, we can achieve high concurrency; good design is often needed to achieve both high concurrency and high performance.
For example, in today's mainstream cloud servers, nginx can easily reach tens of millions of concurrent links in a 32-core 64G configuration; if it is dealing with simple static resource requests, the nginx can reach 100w RPS.
RPS (Requests Per Second) is the number of requests that can be processed per second, which is equivalent to QPS (Queries Per Second), that is, the number of queries that can be processed per second. It is the corresponding number of queries per second by a server, and it is a measure of how much traffic a particular query server handles within a specified period of time.
Second, good expansibility
The expansibility is mainly reflected in the modular design, which is very stable, which makes the ecosphere and third-party modules of Nginx very rich. There are even third-party plug-ins such as Tengine and OpenResty that have created a new biosphere based on him. Rich biosphere and third-party modules provide a guarantee for the rich functions of Nginx.
Third, high reliability
High reliability means that Nginx can run continuously on the server for years, while many web servers often run or for weeks and months, requiring a restart. For Nginx, a reverse proxy server with high concurrency and high performance, it often runs on the edge nodes of the enterprise intranet. At this time, if our enterprise wants to provide 4 9s, 5 9s, or even higher high availability, the downtime for continuous operation of Nginx may only be measured in seconds. So in such a role, the high reliability of Nginx provides us with a very good guarantee.
IV. Hot deployment
Hot deployment refers to upgrading Nginx without stopping the service. This feature is very important for Nginx, because there are millions of concurrent links running on the server. If it is an ordinary server, we can only kill the process and restart it to upgrade. But for Nginx, because directly kill the nginx process will give all the clients that have established a link a very bad experience.
5. BSD license
BSD license means that Nginx is not only open source and free, but we can modify the source code of Nginx in situations where there are customized requirements, and then run it in our business scenario and it is legal.
Nginx composition
Nginx mainly consists of the following four parts:
Nginx binary executable: a file compiled from the source code of each module
Nginx.conf profiles: controlling Nginx behavior
Access.log access log: record every http request information
Error.log error logs: locating issu
Next, we're going to start compiling Nginx.
Compile Nginx# download wget http://nginx.org/download/nginx-1.14.0.tar.gz# extract tar-xzvf nginx-1.14.0.tar.gzcd nginx-1.14.0# configuration. / configure-- prefix=/usr/local/nginx# compile make# install make install
Problems that may be encountered during configure:
. / configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using-without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using-with-pcre= option.
. / configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using-without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using-with-zlib= option.
The reason for the error is that the Nginx module relies on some lib libraries. The solution is as follows:
Install pcre-devel and zlib-devel dependent libraries: yum-y install pcre-devel zlib-develNginx configuration Nginx configuration syntax
Nginx configuration parameters configuration parameters: units of time
Configuration parameters: units of SPAC
Instruction block configured by http
Http: indicates that all instructions are parsed and executed by the http module
Server: resolve the corresponding domain name or a group of domain names
Location:url expression
Upstream: indicates the upstream service. When you need to connect directly to the enterprise intranet service, you can define a upstream.
Example
All the instructions in the example are executed by the http module in Nginx, where server 127.0.0.1 expires 8000 is the domain name to be resolved, location is followed by the corresponding matching rules, expires 3m indicates that the cache is refreshed after 3 minutes, and zone=one:10m indicates that a shared memory space of 10m is opened up for different worker to use.
Summary
This article mainly introduces the reasons and usage scenarios of Nginx, analyzes the advantages of Nginx, and finally starts to compile your own Nginx and make a simple configuration.
Thank you for reading, the above is the content of "the role of Nginx and the method of configuration". After the study of this article, I believe you have a deeper understanding of the role of Nginx and the method of configuration, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.