Nginx web services (manual compilation and installation process)

Nginx Web Services

The concept of Nginx

Nginx (engine x) is a high-performance HTTP and reverse proxy web server, and also provides IMAP/POP3/SMTP services. Nginx was developed by Igor sesoyev for the Ramblerru site (Russian: Pamonep), the second most visited site in Russia. The first public version, 0.1.0, was released on October 4, 2004.
It publishes source code as a BSD like license, known for its stability, rich feature sets, sample profiles, and low system resource consumption. On June 1, 2011, nginx 1.0.4 was released.
Nginx is a lightweight Web server reverse proxy server and email (IMAP/POP3) proxy server, which is distributed under BSD like protocol. It is characterized by less memory and strong concurrency. In fact, the concurrency of nginx is better in the same type of Web servers. Users of nginx websites in mainland China include Baidu, Jingdong, Sina, Netease, Tencent, Taobao, etc.

Nginx manual compilation and installation

Installation environment: Centos7, nginx-1.12.0.tar.gz

The manual compilation and installation process steps of Nginx are as follows:

#Nginx settings
nginx-1.12.0.tar.gz 
1.Decompress package
tar zxf nginx-1.12.0 tar.gz -C /opt/
2.Compile and install environment package required for installation
yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y
3.Create home directory but not home directory
useradd -M -s /sbin/nologin nginx
4.Configure related parameters
cd /opt/nginx-1.12.0
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module 
(Statistics module)
5.Compilation and installation
make &&make install
6.test 
#cd /usr/local/nginx 
#ls
#conf html logs sbin 
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#nginx -t 
nginx 
netstat -natp | grep 80
systemctl stop firewalld.service 
setenforce 0
#yum install -y elinks (test web tools)
#elinks http://localhost 

7.#Basic management
killall -3 (-s QUIT) nginx 
netstat -antp | grep 80
killall -1 (-s HUP) nginx

8.Make management script

Nginx manual compilation and installation instance

[root@localhost ~]# yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y

[root@localhost ~]# cd LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip    php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz  php-7.1.20.tar.bz2
ncurses-5.6.tar.gz         php-7.1.20.tar.gz
nginx-1.12.2.tar.gz        zend-loader-php5.6-linux-x86_64_update1.tar.gz
php-5.6.11.tar.bz2
[root@localhost LNMP-C7]# tar zxf nginx-1.12.2.tar.gz -C /opt/

[root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx

[root@localhost LNMP-C7]# cd /opt/
[root@localhost opt]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module

.....//Omit part of the content
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

[root@localhost nginx-1.12.2]# make && make install
...//Omit part of the content
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/opt/nginx-1.12.2'
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.12.2]# nginx
[root@localhost nginx-1.12.2]# netstat -natp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      66585/nginx: master 
[root@localhost nginx-1.12.2]# systemctl stop firewalld.service 
[root@localhost nginx-1.12.2]# setenforce 0

[root@localhost nginx-1.12.2]# yum install -y elinks
[root@localhost nginx-1.12.2]# elinks http://localhost
//Here, after the command is executed, the dialog box will be displayed, ok enter, enter q, select yes enter, and exit to the original interface

The above is the process of manual compilation and installation of Nginx. Let's introduce the basic management commands of Nginx

Basic management of Nginx

[root@localhost nginx-1.12.2]# Kill - 3 Nginx / / turn off the Nginx service
[root@localhost nginx-1.12.2]# netstat -natp | grep nginx
[root@localhost nginx-1.12.2]# Nginx / / start nginx service
[root@localhost nginx-1.12.2]# Kill - 1 Nginx / / restart the Nginx service
[root@localhost nginx-1.12.2]# netstat -natp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      76326/nginx: master 
//You can also use the following commands to shut down and restart
killall -s QUIT nginx 
killall -s HUP nginx
[root@localhost nginx-1.12.2]# killall -s QUIT nginx
[root@localhost nginx-1.12.2]# netstat -natp | grep nginx
[root@localhost nginx-1.12.2]# nginx 
[root@localhost nginx-1.12.2]# killall -s HUP nginx
[root@localhost nginx-1.12.2]# netstat -natp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      79214/nginx: master 

The above basic management is not convenient. We can make a management script by ourselves. The script is as follows

vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in 
    start)
        $PROG
        ;;
    stop)
        kill -s QUIT $(cat $PIDF)
        ;;
    restart)
        $0 stop 
        $0 start
        ;;
    reload)
        kill -s HUP $(cat $PIDF)
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
esac
exit 0
[root@localhost init.d]# chmod +x nginx 
[root@localhost init.d]# chkconfig -add nginx 
[root@localhost init.d]# service nginx restart 

Summary

This article focuses on the basic points related to Nginx. All we need to know is its own characteristics and the difference between Nginx and Apache.

Features: stability, lightweight, high concurrency, low resources
Advantages: good at handling static website (pictures, text, videos and other files) access resources;

Apache is good at dynamic (for example, the interaction required for account registration)

In the next article, we will introduce how to build a Nginx virtual host based on the manual compilation and installation of Nginx services. Thank you for reading!

Tags: Linux Nginx yum PHP Web Server

Posted on Tue, 24 Dec 2019 05:18:20 -0500 by llirik