1. Understanding Nginx
Nginx ("engine x") is a high performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev for Rambler.ru, the second most visited site in Russia. The first public version, 0.1.0, was released on October 4, 2004. It distributes the source code in BSD-like license form and is known for its stability, rich function set, sample configuration files and low system resource consumption.
2.Nginx Installation
2.1 Nginx Installation Preparations (Related Component Installation)
a. Install the c++ compiler environment, if installed, you can skip it
yum install gcc-c++
b. Install pcre
PCR E (Perl Compatible Regular Expressions) is a Perl library, including Perl-compatible regular expression library. These are useful in performing regular expression pattern matching with the same syntax and semantics as Perl 5.
- Download pcre and decompress it, then install and configure it:
[root@server1 nginx]# wget https://ftp.pcre.org/pub/pcre/pcre2-10.30.tar.gz
[root@server1 nginx]# gunzip pcre2-10.30.tar.gz
[root@server1 nginx]# tar xf pcre2-10.30.tar
[root@server1 pcre2-10.30]# cd pcre2-10.30/
[root@server1 pcre2-10.30]# ./configure
- Compile and install pcre
[root@server1 pcre2-10.30]# make
[root@server1 pcre2-10.30]# make install
c.openssl installation
yum install openssl-devel -y
d. Establishing nginx users
Setting up nginx users and joining corresponding groups will be used in subsequent configurations:
[root@server1 nginx]# useradd -g www www -s /sbin/nologin ##Create the nginx running account WWW and join the WWW group. The www user is not allowed to log in directly to the system.
2.2 Installation of Nginx (source code compilation and installation)
2.1 Download source code (version as stable as possible)
[root@server1 nginx]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
2.2 Decompress the source code and configure it
[root@server1 nginx]# tar zxvf nginx-1.12.1.tar.gz
[root@server1 nginx]# cd nginx-1.12.1
[root@server1 nginx-1.12.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
Note: There may be some problems of lack of dependency in the process of configuration and installation. For the normal installation and operation of the program, please first solve the dependency problem!
Hint to ignore http_rewrite_module module to continue installation
It also reminds us of the lack of openssl library. It was originally installed without openssl and yum.
Go on
Successful as shown in the following figure, then proceed to compile and install
2.3 Compilation and Installation
[root@server1 nginx-1.12.1]# make && make install
2.4 Check if the installation is successful
[root@server1 nginx-1.12.1]# cd /usr/local/nginx/sbin
[root@server1 sbin]# ./nginx -t
The results are as follows:
2.5 Start, Stop, Restart and Test of Services
- start-up
- Method 1
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf - Method 2, enter the nginx directory and start
# cd /usr/local/nginx/sbin
# ./nginx
- Method 1
Basic operation of 2.6 nginx
[root@server1 sbin]# /usr/local/nginx/sbin/nginx ##start-up
[root@server1 sbin]# /usr/local/nginx/sbin/nginx -s stop(quit,reload) ##Stop/Restart
[root@server1 sbin]# /usr/local/nginx/sbin/nginx -h ##Command help
[root@server1 sbin]# / usr/local/nginx/sbin/nginx-t validation configuration file
[root@server1 sbin]# Vim/usr/local/nginx/conf/nginx.conf configuration file
2.7 test
- Testing in Browser
http://ip:80
When the browser appears "welcome to nginx" page, it will start normally: