Guide on switching from distro-provided nginx to nginx built from source?

Steve Holdoway steve at greengecko.co.nz
Thu Mar 13 22:02:03 UTC 2014


On Thu, 2014-03-13 at 15:34 -0400, Jeff Kaufman wrote:
> I haven't been able to find a good guide for people who have been
> using nginx as installed by their linux distribution who want to
> switch to using an nginx they built themselves.  This comes up a lot
> with ngx_pagespeed because for many users we're the first module they
> want which isn't packaged with their distro.  Does this guide exist?
> If not, I might write one for ubuntu at least.
> 
> This is somewhat similar to a regular "install nginx from source"
> guide but it needs to have at least:
> 
> * how to get a list of the modules you need to add (nginx -V | grep
> configure_arguments)
> * how to copy your config over
> * how to keep and modify your nginx init script when uninstalling the
> distro-provided nginx
> * how to do all of this with minimal downtime and risk on a single VPS
> 
> Jeff
> 

A good starting point is to build it up using the current configuration
delivered from your distro. That way you don't need to fool around
moving config files, etc and a reinstall is just to copy /usr/sbin/nginx
into place.

You need a dev environment...

apt-get install build-essential or yum groupinstall "Development Tools"

You'll need a load of dependencies, so expect to run the configure quite
a few times before it succeeds!

And the source code...
cd /usr/local/src
wget http://nginx.org/download/nginx-1.5.11.tar.gz
wget http://nginx.org/download/nginx-1.5.11.tar.gz.asc
gpg --keyserver pgpkeys.mit.edu --recv-key A1C052F
gpg nginx-1.5.11.tar.gz.asc

Code downloaded and verified.
expand the archive and move into it

tar xf nginx-1.5.11.tar.gz
cd nginx-1.5.11

To get the current configuration, use the command

nginx -V 

I use the output to generate a file build.sh which I then modify ready
to run the configure ( this is on ans amazon ec2 server )...

$ cat build.sh

./configure \
  --prefix=/etc/nginx \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/run/nginx.lock \
  --http-client-body-temp-path=/var/cache/nginx/client_temp \
  --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_addition_module \
  --with-http_sub_module \
  --with-http_dav_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_random_index_module \
  --with-http_secure_link_module \
  --with-http_stub_status_module \
  --with-mail \
  --with-mail_ssl_module \
  --with-file-aio \
  --with-ipv6 \
  --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

so I can keep on running

sh build.sh 

until it completes correctly.

then you can run 

make
make install
nginx -t

and if that is successful, restart nginx to get it running. Make sure
you've saved the old version of nginx first, although both rpm and dpkg
offer options to reinstall if necessary.

You can also use this as a starting point to build in ngx_pagespeed
support for example ( good howtos online ).

I also

strip /usr/sbin/nginx 

to drop the debug info. It's way more important to do this if using the
aforementioned extension, as IIRC the end result is over 100MB.

hth,

Steve

-- 
Steve Holdoway BSc(Hons) MIITP
http://www.greengecko.co.nz
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa



More information about the nginx mailing list