Nginx 1.0.6 RPM package SPEC file

Here’s is a SPEC file for building the latest Nginx-v1.0.6 on RHEL/CentOS platform. My Basic modifications are:

    • Nginx would be installed in a dedicated directory named /opt/admon/nginx
    • The Nginx serves as a basic web server. Only a limited amount of modules are enabled. You can update it by tweaking the compiling parameter.

  • The generated package is “nginx-1.0.6-1.admon.x86_64.rpm”, where is also an example for your self-crafted packages’ version control.

It’s tested OK on RHEL-5u7. If you got any issues, please leave a comment for us.

Nginx SPEC file for building RPM package

# cat nginx-stable.spec
%define nginx_user      nginx
%define nginx_group     admon
%define _prefix         /opt/admon/nginx
%define nginx_home      %{_prefix}/lib/nginx
%define nginx_home_tmp  %{nginx_home}/tmp
%define nginx_logdir    %{_localstatedir}/log/nginx
%define nginx_confdir   %{_prefix}/etc
%define nginx_datadir   %{_datadir}/nginx
%define real_name       nginx
%define dist		admon
%define _unpackaged_files_terminate_build 0

Name:           nginx
Version:        1.0.5
Release:	1.%{dist}
Summary:        Robust, small and high performance http and reverse proxy server
Group:          System Environment/Daemons   

# BSD License (two clause)
# http://www.freebsd.org/copyright/freebsd-license.html
License:        BSD
URL:            http://nginx.org/
BuildRoot:      %{_tmppath}/%{real_name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires:      pcre-devel,zlib-devel,perl(ExtUtils::Embed)
Requires:           pcre,zlib
Requires:           perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
# for /usr/sbin/useradd
Requires(pre):      shadow-utils
Requires(post):     chkconfig
# for /sbin/service
Requires(preun):    chkconfig, initscripts
Requires(postun):   initscripts

Source0:    http://sysoev.ru/nginx/nginx-%{version}.tar.gz
Source1:    %{real_name}.logrotate
Source2:    virtual.conf
#Source3:    %{real_name}.init ## Its init script does not contained in this post

%description
This package is built by Admon.Org
The latest version for this is 1.0.6, which can be downloaded from http://sysoev.ru/nginx/.

%prep
%setup -q -n %{real_name}-%{version}

%build
# nginx does not utilize a standard configure script.  It has its own
# and the standard configure options cause the nginx configure script
# to error out.  This is is also the reason for the DESTDIR environment
# variable.  The configure script(s) have been patched (Patch1 and
# Patch2) in order to support installing into a build environment.
export DESTDIR=%{buildroot}
./configure \
    --user=%{nginx_user} \
    --group=%{nginx_group} \
    --prefix=%{nginx_datadir} \
    --sbin-path=%{_sbindir}/%{real_name} \
    --conf-path=%{nginx_confdir}/%{real_name}.conf \
    --error-log-path=%{nginx_logdir}/error.log \
    --http-log-path=%{nginx_logdir}/access.log \
    --pid-path=%{_localstatedir}/run/%{real_name}.pid \
    --lock-path=%{_localstatedir}/lock/subsys/%{real_name} \
    --with-http_realip_module \
    --with-http_gzip_static_module \
    --with-http_stub_status_module \
    --with-cc-opt="%{optflags} $(pcre-config --cflags)"
make %{?_smp_mflags} 

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot} INSTALLDIRS=vendor
find %{buildroot} -type f -name .packlist -exec rm -f {} \;
find %{buildroot} -type f -name perllocal.pod -exec rm -f {} \;
find %{buildroot} -type f -empty -exec rm -f {} \;
find %{buildroot} -type f -exec chmod 0644 {} \;
find %{buildroot} -type f -name '*.so' -exec chmod 0755 {} \;
chmod 0755 %{buildroot}%{_sbindir}/nginx
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{real_name}
%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/%{real_name}
%{__install} -p -d -m 0755 %{buildroot}%{nginx_confdir}/conf.d
%{__install} -p -m 0644 %{SOURCE3} %{buildroot}%{nginx_confdir}/conf.d
%{__install} -p -d -m 0755 %{buildroot}%{nginx_home_tmp}
%{__install} -p -d -m 0755 %{buildroot}%{nginx_logdir}

%clean
rm -rf %{buildroot}

%pre
%{_sbindir}/useradd -c "Nginx user" -s /bin/false -r -d %{nginx_home} %{nginx_user} 2>/dev/null || :

%post
/sbin/chkconfig --add %{real_name}

%preun
if [ $1 = 0 ]; then
    /sbin/service %{real_name} stop >/dev/null 2>&1
    /sbin/chkconfig --del %{real_name}
fi

%postun
if [ $1 -ge 1 ]; then
    /sbin/service %{real_name} condrestart > /dev/null 2>&1 || :
fi

%files
%defattr(-,root,root,-)
%{nginx_datadir}/
%{_sbindir}/%{real_name}
#%{_mandir}/man3/%{real_name}.3pm.gz
%{_initrddir}/%{real_name}
%dir %{nginx_confdir}
%dir %{nginx_confdir}/conf.d
%config(noreplace) %{nginx_confdir}/conf.d/*.conf
%config(noreplace) %{nginx_confdir}/win-utf
%config(noreplace) %{nginx_confdir}/%{real_name}.conf.default
%config(noreplace) %{nginx_confdir}/mime.types.default
%config(noreplace) %{nginx_confdir}/fastcgi_params
%config(noreplace) %{nginx_confdir}/fastcgi_params.default
%config(noreplace) %{nginx_confdir}/fastcgi.conf
%config(noreplace) %{nginx_confdir}/fastcgi.conf.default
%config(noreplace) %{nginx_confdir}/koi-win
%config(noreplace) %{nginx_confdir}/koi-utf
%config(noreplace) %{nginx_confdir}/%{real_name}.conf
%config(noreplace) %{nginx_confdir}/mime.types
%config(noreplace) %{_sysconfdir}/logrotate.d/%{real_name}
%attr(-,%{nginx_user},%{nginx_group}) %dir %{nginx_home}
%attr(-,%{nginx_user},%{nginx_group}) %dir %{nginx_home_tmp}
%attr(-,%{nginx_user},%{nginx_group}) %dir %{nginx_logdir}

%changelog
* Wed Jul 20 2011 Denis Frolov  - 1.0.5-1
- rebuild to 1.0.5

* Sat Jun 05 2011 Denis Frolov  - 1.0.4-1
- rebuild to 1.0.4

* Tue May 26 2011 Denis Frolov  - 1.0.3-1
- rebuild to 1.0.3

* Wed May 11 2011 Denis Frolov  - 1.0.2-1
- rebuild to 1.0.2

* Sun May 10 2011 Denis Frolov  - 1.0.1-1
- rebuild to 1.0.1

* Wed Dec 15 2010 Denis Frolov  - 0.8.54-1
- rebuild to 0.8.54

* Thu Nov 30 2010 Denis Frolov  - 0.8.53-1
- rebuild to 0.8.53

* Wed Jun 16 2010 Denis Frolov  - 0.7.67-1
- rebuild to 0.7.67 * Thu Jun 08 2010 Denis Frolov  - 0.7.66-1
- rebuild to 0.7.66
...

Leave a comment

Your email address will not be published. Required fields are marked *