Compile and install nginx 1.16.0 in CentOS 7 (full version)

I. installation dependency package

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

Dependency package description:

1. Compilation depends on GCC environment, so it needs: gcc-c + +;

2. PCRE(Perl Compatible Regular Expressions) is a perl library, including perl compatible regular expressions library. The http module of nginx uses pcre to parse regular expressions, so it needs to install the pcre library on linux. pcre devel is a secondary development library developed by pcre, so it needs: pcre PCRE devel;

3. Zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the content of http package, so it needs to install zlib library on Centos, so it needs: zlib zlib devel;

4. OpenSSL is a powerful secure socket layer cipher library, which includes main cipher algorithms, common key and certificate encapsulation management functions and ssl protocol, and provides rich application programs for testing or other purposes. nginx not only supports http protocol, but also https (that is, http is transmitted over ssl Protocol). Therefore, OpenSSL library needs to be installed in Centos, so it needs to: OpenSSL OpenSSL devel;

Download the installation package from the official website

wget https://nginx.org/download/nginx-1.16.0.tar.gz

3. Unzip and install

tar zxvf nginx-1.16.0.tar.gz

cd nginx-1.16.0

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

make && make install

IV. test whether the installation is successful

[root@localhost ~]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --prefix=/usr/local/nginx

V. start nginx service

cd /usr/local/nginx/sbin

./nginx

Vi. verify whether the service is started successfully

[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master 

VII. Add nginx service

vi /lib/systemd/system/nginx.service

Insert the following:

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

VIII. Start nginx by service

pkill nginx
systemctl start nginx

IX. check whether the service is started

[root@localhost sbin]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-04-29 23:19:39 EDT; 18min ago
  Process: 348 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 349 (nginx)
    Tasks: 2
   Memory: 976.0K
   CGroup: /system.slice/nginx.service
           ├─349 nginx: master process /usr/local/nginx/sbin/nginx
           └─350 nginx: worker process

Apr 29 23:19:39 localhost.localdomain systemd[1]: Starting nginx...
Apr 29 23:19:39 localhost.localdomain systemd[1]: Started nginx.
[root@localhost sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master p 

X. configure nginx service to start automatically

[root@localhost sbin]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

Centos7 nginx 1.16.0 reverse agent compilation and installation

yum -y install gcc-c++
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --user=nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --with-pcre --add-module=/usr/local/fastdfs-nginx-module-1.20/src/

make && make install
useradd nginx
#test
/usr/local/nginx/sbin/nginx -v
/usr/local/nginx/sbin/nginx
netstat -ntlp |grep 80

Keywords: Nginx OpenSSL zlib yum

Added by bluegreen1 on Fri, 08 Nov 2019 21:00:13 +0200