How to compile and install nginx 1.20.2 under Centos7.9

created at 05-30-2022 views: 15

system environment

  • System platform: CentOS 7.9
  • Nginx version: nginx-1.12.2.tar.gz
  • Pcre version: pcre-8.42.tar.gz
  • Required dependencies: gcc-c++ libtool
  • Third-party library: zlib zlib-devel openssl openssl-devel pcre

The Centos7.9 operating system environment is installed in a simplified way, and some packages that depend on nginx need to be installed.

Install dependencies

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

compile the pcre library

download:

wget https://sourceforge.net/projects/pcre/files/pcre/8.42/pcre-8.42.tar.gz
tar zvxf pcre-8.42.tar.gz
mv pcre-8.42 /usr/local/ && cd /usr/local/pcre-8.42
./configure && make && make install

compile Nginx

Download:

wget http://nginx.org/download/nginx-1.12.2.tar.gz
useradd -s /sbin/nolgoin nginx
tar xf nginx-1.12.2.tar.gz

cd nginx-1.12.2 &&
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.42 --user=nginx --group=nginx

make && make install

#Display compiled modules
/usr/local/nginx/sbin/nginx -V 
#Display nginx version
/usr/local/nginx/sbin/nginx -v

Check that the nginx configuration file is correct:

> nginx -t
# bellow means success
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

common commands

/usr/local/nginx/sbin/nginx # Start Nginx
/usr/local/nginx/sbin/nginx -s reload # Reload the configuration file
/usr/local/nginx/sbin/nginx -s reopen # restart Nginx
/usr/local/nginx/sbin/nginx -s stop # Quickly shut down Nginx
/usr/local/nginx/sbin/nginx -s quit # Close Nginx
created at:05-30-2022
edited at: 05-30-2022: