The following procedure describes How To build a Nginx .deb package using the developer's latest sources.
# Tested on Ubuntu 10.04
Published at: <http://ubuntuforums.org/showthread.php?p=6953724>
Nginx <http://nginx.net/> is an open-source Web Server. It is a high-performance HTTP server that uses very low server resources, is reliable and integrates beautifully with Linux.
Besides being a web server it can also be used as reverse proxy and IMAP/POP3 proxy server.
## install needed debian tools
sudo aptitude -R install build-essential devscripts fakeroot debhelper autotools-dev libpcre3-dev libssl-dev zlib1g-dev # libgcrypt11-dev
## search bellow & replace by your own version number, maintainer name, maintainer email, domain:
0.8.52
dummy
dummy@example.com
example.com
## get latest STABLE nginx from the author's site: <http://sysoev.ru/nginx/download.html>
cd $(mktemp -d) ; # create a temp dir and cd to it
wget http://sysoev.ru/nginx/nginx-0.8.52.tar.gz
## get the sources from the debian/ubuntu repositories
apt-get source nginx
sudo apt-get build-dep nginx
cd $(ls -d nginx*/)
## update package info to new version
(export DEBFULLNAME='dummy';export DEBEMAIL='dummy <dummy@example.com>';uupdate --upstream-version 0.8.52 ../nginx-0.8.52.tar.gz)
cd ../"$(dpkg-parsechangelog | sed -n 's/^Source: //p')-0.8.52"
sed -i '/^Maintainer/s/: .*/: dummy <dummy@example.com>/;/^Uploaders/s/: .*/: dummy <dummy@example.com>/;/XSBC-Original-Maintainer/d' debian/control; # customize maintainer data
## 10.04 OPTIONAL: set ./configure & debian/rules, to our own specs
# see nginx compile-time options at: <http://wiki.nginx.org/NginxInstallOptions>
# REMEMBER TO CAREFULLY (RE)CHECK ANY CONFIG CHANGES
sed -i '/nginx-upstream-fair.diff/d' debian/patches/series
rm debian/patches/nginx-upstream-fair.diff
grep -A 20 '\.\/configure' debian/rules
sed -i '/with-debug/,/nginx-upstream-fair/ c\
\t--with-http_ssl_module \\\
\t--without-http_limit_req_module \\\
\t--without-mail_pop3_module \\\
\t--without-mail_smtp_module \\\
\t--without-mail_imap_module \\\
\t--without-http_uwsgi_module \\\
\t--without-http_scgi_module \\\
\t--without-http-cache \\
' debian/rules
grep -A 20 '\.\/configure' debian/rules
# OPTIONAL: anonymize nginx public fingerprint
# do replace 0.0.00 and webserver by your own values
sed -i '/^#define nginx_version/s/[0-9]/0/g;/^#define NGINX_VERSION/s/".*"/"0.0.00"/;/define NGINX_VER\([ \t]*\)"/s/nginx/webserver/' src/core/nginx.h
sed -i '/SERVER_SOFTWARE/s/nginx/webserver/' debian/conf/fastcgi_params
sed -i '/our $VERSION/s/[0-9]/0/g' src/http/modules/perl/nginx.pm
sed -i '/>nginx</s/nginx/ /' src/http/ngx_http_special_response.c
# check if all went well
grep -i nginx_ver src/core/nginx.h
grep SERVER_SOFTWARE debian/conf/fastcgi_params
grep 'our $VERSION' src/http/modules/perl/nginx.pm
grep -i nginx src/http/ngx_http_special_response.c
## OPTIONAL: to edit the change log use:
#(export DEBFULLNAME='dummy';export DEBEMAIL='dummy <dummy@example.com>';dch -i);
## build the new package
(export DEBFULLNAME='dummy';export DEBEMAIL='dummy@example.com';debuild -i -us -uc);
## install the newly built package
cd ..
sudo dpkg -i nginx_0.8*deb && sudo aptitude hold nginx
## OPTIONAL: customize /etc/nginx/nginx.conf
grep 'tcp_\|worker_processes\|gzip\|keepalive_timeout\| tokens\|sendfile' /etc/nginx/nginx.conf
# set worker_processes = server CPU's
sudo sed -i '/^worker_processes/s/1;/'"$(grep -c processor /proc/cpuinfo)"';/' /etc/nginx/nginx.conf
# change gzip
(n=$'\n' ; sudo sed -i "/^\([ \t]*\)gzip\([ \t]*\)on;/ a\\${n} gzip_min_length 640; \\${n} gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;" /etc/nginx/nginx.conf);
# set timeout to 10
sudo sed -i '/^\([ \t]*\)keepalive_timeout/s/keepalive_timeout.*/keepalive_timeout\t10;/' /etc/nginx/nginx.conf;
# set server_tokens off
(n=$'\n' ; sudo sed -i "/^\([ \t]*\)sendfile\([ \t]*\)on;/ a\\${n} server_tokens off;" /etc/nginx/nginx.conf);
# set tcp_nopush on
sudo sed -i '/#tcp_nopush/s/#//' /etc/nginx/nginx.conf;
grep 'tcp_\|worker_processes\|gzip\|keepalive_timeout\| tokens\|sendfile' /etc/nginx/nginx.conf
## replace nginx trying to not disrupt the web services
pgrep nginx && sudo kill -s USR2 $(cat /var/run/nginx.pid)
pgrep nginx >/dev/null && sudo kill -s QUIT $(cat /var/run/nginx.pid.oldbin)
sleep .5
pgrep nginx || sudo /etc/init.d/nginx start
sudo /usr/sbin/nginx -t && /etc/init.d/nginx status
## OPTIONAL: to turn debug mode on:
./configure --with-debug ...
nginx.conf:
events {
debug_connection your.ip.address;
}
--
Resources:
Rebuilding Debian packages <http://www.debian-administration.org/articles/20>
Nginx page <http://nginx.net/>
Nginx Wiki <http://wiki.nginx.org/Main>
Nginx Forum <http://forum.nginx.org/>
Bookmarks