1. 安装rpm构建工具
yum -y install rpm-build redhat-rpm-config
2.下载nginx并解压
tar zxvf nginx-16.1.tar.gz
3. 进入rpm目录
vi /root/rpmbuild/SPECS
Summary: High Performance Web Server
Name: nginx
Version: 1.16.1
Release: el5
License: GPL
Group: Applications/Server
Source: http://nginx.org/download/nginx-%{version}.tar.gz
URL: http://nginx.org/
Distribution: Linux
Packager: yunjianfei <yunjianfei1987@gmail.com>
BuildRoot: /data/%{name}-%{version}-%{release}
#nginx解压后的源文件位置
%define srcdir /home/soft/nginx-1.16.1
%description
nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server
%prep
%build
cd %{srcdir}
./configure --prefix=/usr/local/nginx --add-module=/home/soft/fastdfs-nginx-module/src
make -j8
%install
cd %{srcdir}
make DESTDIR=%{buildroot} install
%preun
if [ -z "`ps aux | grep nginx | grep -v grep`" ];then
killall nginx >/dev/null
exit 0
fi
%files
/usr/local/nginx
4. 执行rpmbuild命令,打rpm包
rpmbuild -bb nginx.spec
5. 安装nginx
cd /root/rpmbuild/RPMS/x86_64
rpm -Uvh *.rpm --nodeps --force
6. 启动nginx
/usr/local/nginx/sbin/nginx