Building an Nginx RPM on Amazon’s Linux

If no customizations are desired, a far simpler way to get the RPM, than that outlined below, is to use the nginx repository, available from nginx’s download page.

After deciding to change my server stack today (based on Amazon’s Linux), I noted that, despite the current version of Amazon’s Linux being hardly a few days old, the repository has many ‘legacy’ version of the software I use (nginx, postfix, etc.). Additionally, EPEL does not add versions that break backward compatibility, so more recent versions are not always readily available from there.

Get the latest EL6 SRPM from rpmfind (If you can find it directly in EPEL, even better)

cd /usr/local/src/
wget ftp://195.220.108.108/linux/epel/testing/6/SRPMS/nginx-1.0.5-1.el6.src.rpm
rpm -ivh nginx-*.src.rpm
cd /usr/src/rpm/SPECS

You can find the configure parameters for your current install of nginx by running nginx -V

Edit the spec file:

vi nginx.spec

Change ‘Version’ (to 1.0.8) [line 11]

Due to the modules I have removed below, the corresponding dependencies are removed here. If you need any of these modules (Perl, GeoIP, libxslt), then don’t remove the associated dependencies.

Change [lines 22-25]:

BuildRequires:      pcre-devel,zlib-devel,openssl-devel,perl-devel,perl(ExtUtils::Embed)
BuildRequires:      libxslt-devel,GeoIP-devel,gd-devel
Requires:           pcre,openssl,GeoIP,gd
Requires:           perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))

To: (line 25 was removed entirely)

BuildRequires:      pcre-devel,zlib-devel,openssl-devel
BuildRequires:      gd-devel
Requires:           pcre,openssl,gd

You can find the specifics of the configure parameters in the Nginx Wiki
Change ‘configure’ (to remove extraneous modules) [line 68]

./configure \
    --user=%{nginx_user} \
    --group=%{nginx_group} \
    --prefix=%{nginx_datadir} \
    --sbin-path=%{_sbindir}/%{name} \
    --conf-path=%{nginx_confdir}/%{name}.conf \
    --error-log-path=%{nginx_logdir}/error.log \
    --http-log-path=%{nginx_logdir}/access.log \
    --http-client-body-temp-path=%{nginx_home_tmp}/client_body \
    --http-proxy-temp-path=%{nginx_home_tmp}/proxy \
    --http-fastcgi-temp-path=%{nginx_home_tmp}/fastcgi \
    --http-uwsgi-temp-path=%{nginx_home_tmp}/uwsgi \
    --http-scgi-temp-path=%{nginx_home_tmp}/scgi \
    --pid-path=%{_localstatedir}/run/%{name}.pid \
    --lock-path=%{_localstatedir}/lock/subsys/%{name} \
    --with-http_ssl_module \
    --with-http_gzip_static_module \
    --with-http_realip_module \
    --with-cc-opt="%{optflags} $(pcre-config --cflags)"

Delete [line 145]:

%{_mandir}/man3/%{name}.3pm.gz

Delete [lines 167-169]:

%dir %{perl_vendorarch}/auto/%{name}
%{perl_vendorarch}/%{name}.pm
%{perl_vendorarch}/auto/%{name}/%{name}.so

Save the spec file, and build RPM:

rpmbuild -bb nginx.spec

It takes around 5 minutes to build on a t1.micro. The RPM is located in /usr/src/rpm/RPMS/i686.

Install with (the --nogpgcheck option is required since the RPM has not been signed):

yum install --nogpgcheck nginx-1.0.8-1.amzn1.i686.rpm

By cyberx86

Just a random guy who dabbles with assorted technologies yet works in a completely unrelated field.

1 comment

Leave a comment

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