It only takes three minutes to take you to quickly master Nginx services!, The main role of nginx in server deployment

1 year ago (2024-01-18) Chief Editor
15 minutes
two hundred and twenty-six
zero

Nginx (engine x) is an open source WWW service and proxy service software with high performance, high concurrency and high reliability.

Developed by Igor Sysoev, a Russian, the author will open source the source code in the form of BSD like license for global use.

In 2019, F5 will acquire NGINX, with a total value of about US $670 million. F5 load balancing manufacturer.

Open source means that the source code of Nginx can be obtained directly and used for free.

High performance means very fast processing speed and low resource consumption.

High concurrency, supports concurrent connections from 10000 to 50000, and consumes low resources.

High reliability is reflected in the very stable service.

50000 concurrency refers to small static files, NGINX (50000 concurrency)+PHP (700 concurrency).

Select Nginx reason

1. Open source, free

2. Powerful and simple to use

3. High performance and high concurrency

4. High reliability and scalability (many modules, developing third-party modules)

5. The community is active (top 10000 Internet websites), ranking No.1, and growing fast.

Nginx ecological status

OpenResty? It is a high-performance Web platform based on Nginx and Lua. It integrates a large number of sophisticated Lua libraries, third-party modules and most dependencies

It is used to easily build dynamic Web applications, Web services and dynamic gateways that can handle ultra-high concurrency and have high scalability. Born in 2007

Kong Gateway is a highly available and extensible API Gateway project written based on OpenResty (Nginx+Lua module) and open source by Mashape

Based on NGINX and Apache Cassandra or PostgreSQL, Kong can provide easy-to-use RESTful APIs to operate and configure the API management system, so it can horizontally expand multiple Kong servers, distribute requests evenly to each server through the front-end load balancing configuration, and deal with large quantities of network requests

Lua is the script language, nginx+Lua is the script language, which filters and controls requests

MySQL proxy read-write separation software is developed using Lua

Tengine is a web server project initiated by Taobao( //tengine.taobao.org/ )

Nginx Enterprise Applications

As web service software

Nginx is a web service software that supports high performance and high concurrency. It has many superior features. As a web server, compared with Apache, Nginx can support more concurrent connection access, but it occupies less resources, is more efficient, and is also very powerful in function, almost no less than Apache. Moreover, Nginx updates more frequently, and the community users are more popular.

1. Nginx is a static Web service software that uses Nginx to run HTML, JS, CSS, small pictures and other static data (this function is similar to lighttpd software), apache, lighttpd, IIS, Node.js

2. Support dynamic static separation function apache, lighttpd, IIS

3. Support dynamic Web service extension PHP (fastcgipass) JAVA (proxypass) Python (uwsgipass) memcache (memcachepass)

Nginx combines FastCGI to run PHP dynamic programs (using fastcgipass mode)

Nginx and proxypass support tomcat dynamic programs (using proxypass)

Nginx and uwsgipass support Python (using uwsgipass)

4. The whole site HTTPS supporting secure Web services (https) consumes performance. In fact, https can be used for login and https can be used for payment

As reverse proxy or load balancing service software

In terms of reverse proxy or load balancing services, Nginx can be used as a proxy server for dynamic services such as Web services, PHP/Tomcat/Python, and Memcached caches. It has similar functions to professional reverse proxy software (such as Haproxy), and is also an excellent mail proxy service software (one of the purposes of developing this product first was also to serve as a mail proxy service), In terms of Nginx proxy function, it has supported TCP and UDP proxy, and Nginx proxy function has become more and more powerful

1. Similar load balancing software: haproxy, lvs, hardware: F5, netscalernginx only supported http in the early days, but now it also supports tcp/udp. Support tcp load: load mysql and application services.

2. Emphasis on the difference between reverse proxy and load balancing

Forward proxy: from inside to outside. Replace the low efficiency PC in the LAN and request external application services.

Reverse proxy: from outside to inside, replace, low efficiency replace external users to request internal application servers.

Load balancing: forward, high efficiency (LVS) shake off the shopkeeper, and throw back the request.

3. Load Balancing and the Trend of Web Services

Cache server

In terms of Web cache services, Nginx can implement the functions of professional cache software such as Squid through its proxycache module.

Common cache software: squid, varnish, nginx, ats

Summary of main application scenarios of Nginx

1. Static Web server: use Nginx to run HTML, JS, CSS, small pictures and other static data (this function is similar to lighttpd software).

2. Running a dynamic Web server together: Nginx runs PHP and other dynamic programs in combination with FastCGI (for example, using the fastcgipass mode). Nginx, together with proxypass, supports Java dynamic programs (tomcat/resin services). Nginx supports Python in combination with uwsgipass.

3. Reverse proxy/load balancing http load balancing

4. Do a Web cache server (put files into memory).

5. Support secure web services (https)

Nginx core features

Small static files are highly concurrent, occupy less resources, and the software itself is small

1. Support high concurrency: support tens of thousands of concurrent connections (especially in the static small file business environment)

2. Low resource consumption: Under 30000 concurrent connections, 10 Nginx threads will consume less than 200MB of memory

3. It can be used for HTTP reverse proxy and accelerated cache, that is, load balancing function. The built-in health check function for RS node server is equivalent to the function of professional haproxy software or lvs. With the cache function of professional cache software such as squid

Differences between Nginx epoll model and Apache select model

Nginx uses the latest epoll (Linux 2.6 kernel) and kqueue (freebsd) asynchronous network I/O models, while Apache uses the traditional select model

At present, Squid and Memcached software that can withstand high concurrent access under Linux use epoll model

Brief summary:

1. Epoll and select network IO processing model

2. Epoll asynchronous network IO model, supporting high concurrency

3. Select the traditional network IO model, with high concurrency and weak ability

4. Apache uses the traditional select model, and Nginx uses the high concurrency epoll model

Asynchronous and synchronous: and the case of asynchronous static

Overview of network IO model

Generally speaking, network IO can be abstracted as data exchange between user mode and kernel mode. One network data read operation can be divided into two steps:

1. Network card driver waits for data to be ready (kernel state)

2. Copy data from kernel space to process space (user mode)

According to the different processing methods of these two steps, we usually divide network IO into blocking IO and non blocking IO

Nginx software core composition

1. Nginx executable commands:

It is a binary file built by Nginx framework and related modules. This file is equivalent to the car itself, and all functions are provided by it

2. Nginx.conf configuration file:

It is equivalent to the driver. Although the binary executable file has provided many functions, whether these functions are enabled or what actions are defined to handle requests after they are enabled is determined by the nginx. conf file, so it is equivalent to the driver of the car, controlling the behavior of the car

3. Access log access.log:

It is equivalent to the GPS track formed when the car passes through all places. Access.log will record every HTTP request information and response information processed by Nginx

4. Error log error.log:

It is equivalent to the black box of an aircraft. When unexpected problems occur, you can locate them through error.log

Nginx software installation

Yum installation

Configure nginx source

#Method 1: # vim/etc/yum. repos. d/nginx. repo [nginx stable] name=nginx stable repobaseurl= //nginx.org/packages/centos/ $releasever/$basearch/gpgcheck=1enabled=1gpgkey= //nginx.org/keys/nginxsigning.keymodulehotfixes=true# Method 2: # Non interactive operation, pay attention to escape characters # cat>/etc/yum.repos.d/nginx.repo<

Install and Start

Yum install nginx - yrpm - qa nginx # If you start the http service on the server, you must first turn off the http service systemctl stop httpdsystemctl disable httpd # Start the nginx service systemctl start nginx systemctl enable nginx systemctl status nginx # Verify whether the final installation is correct wget 10.0.0.7 # Change the IP address to the IPcurl 10.0.0.7 # Change the IP address to the self server Server IP or browser access

Compile Install

Download source package

mkdir -p /server/toolscd /server/toolswget //nginx.org/download/nginx-1.20.1.tar.gz

Installation dependency

#Rewrite regular related pcre: URL rewriting software to achieve pseudo static URL jump, SEO optimization yum install pcre pcre devel - y # https encryption access using it yum install openssl openssl devel - y

Compile Installation Steps

Userdel - r wwwuseradd - u 1111-s/sbin/nologin www - M # Unzip the nginx compressed package tar xf nginx 1.20.1. tar. gzcd nginx 1.20.1/ln - s/application/nginx 1.20.1//application/nginx # Specify nginx user permissions and compile and install them/ Configure -- user=www -- group=www -- prefix=/application/nginx - 1.20.1/-- with httpstubstatusmodule -- with httpsslmodule -- with pcremakemake install # nginx start check lsof - i: 80/application/nginx/sbin/nginx - t/application/nginx/sbin/nginx stat - lntupgrep nginx

Verify that the final installation is correct

Wget 10.0.0.8 # Change the IP address to your own server's IP curl 10.0.0.8 # Change the IP address to your own server's IP or browser access

The function of the configure parameter

Configure nginx PATH environment variable

#Add vim/etc/profileexport PATH="/application/nginx/sbin/: $PATH" # to the/etc/profile file to make it effective/ Etc/profile # Check and test echo $PATHnginx - t

Configure systemd startup mode

# vim /usr/lib/systemd/system/nginx.service[Unit]Description=The nginx HTTP and reverse proxy serverAfter=network-online.target remote-fs.target nss-lookup.targetWants=network-online.target[Service] Type=forkingPIDFile=/application/nginx/logs/nginx.pidExecStartPre=/usr/bin/rm -f /application/nginx/logs/nginx.pidExecStartPre=/application/nginx/sbin/nginx -tExecStart=/application/nginx/sbin/nginxExecReload=/application/nginx/sbin/nginx -s reloadKillSignal=SIGQUITTimeoutStopSec=5KillMode=processPrivateTmp=true[Install] WantedBy=multi-user.target# chmod +x /usr/lib/systemd/system/nginx.service# systemctl enable nginx# pkill nginx# systemctl start nginx# lsof -i :80

Original source: //www.oldboyedu.com/blog/4332.html

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/4205.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

What technologies have been applied and developed in the field of new media, and the application of new technologies in media

In the field of new media, many technologies have been applied and developed. These include: cloud computing: cloud computing technology enables new media companies to develop and deploy applications more quickly, and can dynamically adjust resources according to needs. Big data: New media companies can use big data technology to analyze massive user data, understand user preferences, behavior habits and other information
nine hundred and seventy-one
one
1 year ago (2024-02-20)

WMS warehouse management system, promoting the transformation of warehousing from extensive to fine management, WMS warehouse management

Warehousing is extremely important for the manufacturing industry and is an important guarantee for the survival and development of manufacturing enterprises. However, with the expansion of manufacturing enterprises' business, the traditional warehouse management has been unable to respond to business changes quickly. The extensive management mode not only makes the warehouse operation not smooth, but also increases the storage cost. Therefore, it is necessary for manufacturing enterprises to deploy a WMS warehouse management system
eight hundred and forty-eight
one
1 year ago (2024-02-20)

How to select MES system? Main contents of MES production management

Original title: How to select MES system? The main content of MES production management Production and manufacturing activities are the core activities of manufacturing enterprises. As the entity unit of manufacturing activities, planning objectives and the realization of enterprise value, workshop management is the focus of enterprise management. With the rapid development of manufacturing industry, MES is the focus and current hot spot of manufacturing enterprise information automation system
nine hundred and sixty-four
zero
1 year ago (2024-02-20)

The WeChat management system can manage the information content of WeChat more effectively. Let's manage the data of WeChat here

Original title: WeChat management system manages the information content of WeChat more effectively. Many enterprises will assign work to WeChat, because no one wants their personal WeChat to mix work and other related knowledge, but someone will always use the company's loopholes to do something harmful to the company's interests. Don't think such things are rare. I learned about a media financing company in Shenzhen. They have 3
seven hundred and seventy-seven
zero
1 year ago (2024-02-19)

Student electronic file management system, three-dimensional communication space of "home", "school" and "community", and school electronic files

In the era of big data, in the process of recording the growth of students, the school reexamines the management of student files, moves with the times, and promotes the reform of student growth files with new thinking. "Electronic files of primary and secondary school students' growth records" have been gradually introduced into educational management, and show vigorous vitality. Student file management system is an indispensable part of the school, its content for the school
five hundred and seventy-one
zero
1 year ago (2024-02-19)

Ruizhe Information: Select Sitecore? Or... just six steps to choose a content management system, Ruizhe Information Technology Service Co., Ltd

The content management system (CMS) is an important part of the success of website construction. At present, the content management system on the network is relatively complex. It is not easy to find a good content management system that is very suitable for the current digital marketing environment. Before we compare the functionality, operation, scalability, security and other specific performance of the major CMS systems, we need to achieve
three hundred and forty-three
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: