1.安装依赖包

yum -y install zip unzip gcc gcc-c++ automake \
autoconf libtool make glibc gd-devel pcre-devel \
libmcrypt-devel mhash-devel libxslt-devel libjpeg \
libjpeg-devel libpng libpng-devel freetype \
freetype-devel libxml2 libxml2-devel zlib \
zlib-devel glibc glibc-devel glib2 glib2-devel \
bzip2 bzip2-devel ncurses ncurses-devel curl \
curl-devel e2fsprogs e2fsprogs-devel krb5 \
krb5-devel libidn libidn-devel openssl \
openssl-devel libevent libevent-devel

2.显示pcre-devel 信息

yum info pcre-devel

3.创建nginx用户

groupadd nginx
useradd -s /sbin/nologin -M nginx -g nginx

4.下载解压

cd /data/soft
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xf nginx-1.18.0.tar.gz

5.编译安装

cd nginx-1.18.0/
./configure \
--prefix=/data/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
make && make install

6.启动服务

/data/nginx/sbin/nginx

7.开启开机自启

vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: 2345 97 25
#description nginx-server-scryt
nginx=/data/nginx/sbin/nginx
case "$1" in
  start )
        netstat -anlpt | grep ngin[x]
        if [ $? -eq 0 ]
         then
           echo "nginx service is running!"
        else
           echo "nginx service runing!"
           $nginx
        fi
      ;;
  restart)
        $nginx -s reload
        if [ $? -eq 0 ]
         then
           echo "nginx server is begin restart"
        else
           echo "nginx server restart"
        fi
      ;;
     stop)
         $nginx -s stop
        if [ $? -eq 0 ]
         then
           echo "nginx server is stop"
        else
           echo "nginx server stop,try again"
        fi
      ;;
   status)
        netstat -anlpt | grep ngin[x]
        if [ $? -eq 0 ]
         then
            echo "nginx server is running!"
        else
            echo "nginx server is not runing.try to restart"
        fi
      ;;
     *)
      echo "Please enter (start|restart|stop|status)"
      ;;
esac
exit 0

8.加执行权限

chmod +x /etc/init.d/nginx

9.加入开机自启

vim /etc/rc.local
/etc/init.d/nginx start
chkconfig --add nginx

10.修改环境变量

vim /etc/profile
export PATH="$PATH:/data/nginx/sbin/"
source /etc/profile