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

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

For testing the new binary and being able to revert quickly to the other
one, use the advice on this documentation page:
http://nginx.org/en/docs/control.html

That way, you will have virtually no downtime and only stop the old
nginx
process when you decide the new one is doing its job.

B. R.

On Thu, 2014-03-13 at 15:34 -0400, Jeff Kaufman wrote:

  • 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 H. BSc(Hons) MIITP
http://www.greengecko.co.nz
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa

Maybe this will help
http://www.howtoforge.com/using-ngx_pagespeed-with-nginx-on-debian-wheezy
and
http://www.howtoforge.com/using-ngx_pagespeed-with-nginx-on-debian-jessie-testing

  • right up your alley for Debian distro :slight_smile:

I personally use CentOS build via Centmin Mod Nginx as it already
includes
ngx_pagespeed support out of the box
http://centminmod.com/nginx_ngx_pagespeed.html :slight_smile:

As to minimal downtime and risk, easiest would be to do a test run
first,
DigitalOcean VPS charged on an hourly basis is a good platform to do
testing
for end users wanting to make the jump from pre-packaged Nginx builds to
source compilation. I suppose you could even automate the entire
transition
and shell script something to do all the leg work.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,248335,248342#msg-248342

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs