Introduction and installation of nginx (1)

1. Basic introduction

1.1 Basic information

Nginx is a high-performance web server. In addition to it, Apache, Tomcat, Jetty, IIS, they are all Web servers, or WWW (World Wide Web) servers, and they also have the basic functions of Web servers.

nginx performance is high. Can be accessed by a large amount. Moore's Law

Apache dynamic page stability

nginx handles static pages, and high concurrency is relatively stable.

nginx is developed in C language

1.2 Nginx advantages and disadvantages

advantage:

nginx application scenarios,

1. Static resource service. (Local file system response service)

2. Provide reverse proxy service, powerful performance. Cache function, load balancing module to achieve high concurrency

3.api

nginx market share: about 30%

Great use of operating system, memory consumption is relatively small (official test 3w, 10 nginx. Only 150M memory)

Official 5w concurrency

Simple configuration file, few modules

BSD license is relatively low cost. Open source

Good stability

The scalability is better and the documentation is comprehensive. Easy secondary development.

Support hot deployment.

Disadvantages:

 Without apache single process, it is not so stable. Redirection rules are not as powerful as Apache.

apache:

Apache has a long period of development, and it is currently the world ’s undisputed largest web server. It has many advantages, such as stability, open source, and cross-platform. The scale of the Internet industry is far less than it is today, so it is designed as a heavyweight Web server that does not support high concurrency. On the Apache server, if there are tens of thousands of concurrent HTTP requests accessing at the same time, it will cause a lot of memory consumption on the server, and the operating system kernel will also consume a lot of CPU resources for inter-process switching of hundreds of Apache processes, and cause The average response speed of HTTP requests is reduced, which determines that Apache cannot become a high-performance web server

2.0 download

Configure and use in Linux

download

Official website address: http://nginx.org/

Go to page

The mainline version is the latest version. However, we generally do not choose to use it without testing.

Generally choose to use the stable version

click to download

Upload to Linux via xftp

3.0 Directory Introduction

3. Unzip via command

tar -zxvf nginx-1.16.1.tar.gz 

Enter the nginx directory

 

3.1 auto directory 

   There is cc, which is the file used for compilation. os is to judge the characteristics of the operating system and provide it to nginx

    Other files are compiled with auxiliary conf configuration files

3.2 CHANGES directory

Record version release and bug fixes

3.3 CHANGES.ru

Because the author is Russian, an els version is provided

3.4 conf directory

This is convenient for operation and maintenance personnel to configure, the more important is nginx.conf. These are sample files. I will copy when I install

3.5 contrib directory

vim directory, provides syntax detection

We can copy to the home directory

cp -r vim / * - /. vim

3.6html directory

The default publishing directory. And the default access page, and the error page reported by nginx

3.7src directory

nginx source code

 

4 installation


 

4.1 Basic installation conditions

Four to be installed

1. GCC-GNU compiler collection, which can be used to compile C language programs. Nginx does not directly provide binary executable programs, only download the source code to compile.

yum -y install gcc

2. PCRE library (Nginx compilation requires PCRE (Perl Compatible Regular Expression), a function library developed by Philip Hazel, currently used by many software, the library supports regular expressions.

yum install -y pcre-devel

3. The zlib library (zlib library provides developers' compression algorithms, gzip compression is required in various modules of Nginx.), Zlib library is used to compress the content of the HTTP package in gzip format, if we are in nginx.conf It is configured with gzip on, and specifies that certain types (content-type) HTTP responses are compressed using gzip to reduce network transmission.

yum install -y zlib-devel

4.OpenSSL library (In Nginx, if the server will use the OpenSSL library when providing a secure webpage, we need to install the library file and its development installation package (openssl and openssl-devel).) To support HTTP, you also need to transfer HTTP over the more secure SSL protocol, so you need to have OpenSSL. In addition, if we want to use MD5, SHA1 and other hash functions, we also need to install it.

yum -y install openssl-devel

 

Of course, it can also be solved in one sentence:

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel

 

4.2 Installation commands

 

============> Compile nginx

./configure --prefix=/usr/local/nginx

The advantage of using the —prefix option is to uninstall the software or migrate the software. When a certain installed software is no longer needed, simply delete the installation directory, you can uninstall the software cleanly; transplant software only need to copy the entire directory to another machine (same operating system). Of course you can also use the default

============>make

make

After make, you can go to the intermediate directory objs to view

 

============> make install (only used in the first installation. If the version is updated, it cannot be used)

make install

At this time, you can see that nginx is generated in the directory we specified

There are four directories inside, which are copied from our installation directory

There is a script to start nginx in sbin

5.0 Configuration after installation

Enter our installation directory

cd /usr/home/nginx/sbin

Start command test

./nginx

View port, nginx starts port 80 by default

 netstat -tnlp

 

At this time, access the server address through a browser and access the default welcome page

Startup complete

 

 

6. Other error reports:

Because nginx is written in C language, you need to install the gcc compiler

yum -y install -y gcc

If error 2

To detect http rewrite module, pcre library is required

If error 3

gzip. Compressed pictures are used, the webpage may encounter high-definition pictures, and enter a few G pictures. So use compression

yum install -y zlib-devel

 

If error 4

make: *** No rule to make target build', needed bydefault’. Stop.

Then simply install the following four elements.

 

And then execute configure === make == make install 

Compile

./configure --prefix=/usr/local/nginx

make

make

make install

make install

 

Published 115 original articles · Like 58 · Visits 160,000+

Guess you like

Origin blog.csdn.net/luChenH/article/details/104761682