Ben Ripkens

back to blog index

How-to install nginx

Since there is so much buzz around nginx, I wanted to give it a try on my small home server. The server is running a desktop edition of Ubuntu 10.04 (I keep it as backup machine in case my laptop breaks), so keep this in mind. The following bash script will download nginx version 1.1.12, its dependencies and install it. Also, a user nginx will be created.

# Start by creating an appropriate user
useradd -r nginx
mkdir /home/nginx
chown nginx:nginx /home/nginx/

# Retrieve nginx dependencies
cd /home/nginx
mkdir library
cd library
wget http://zlib.net/zlib-1.2.5.tar.gz
tar xfz zlib-1.2.5.tar.gz
rm zlib-1.2.5.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar xfz pcre-8.21.tar.gz
rm pcre-8.21.tar.gz
cd ..

# Installing nginx
wget http://nginx.org/download/nginx-1.1.12.tar.gz
tar xfz nginx-1.1.12.tar.gz
rm nginx-1.1.12.tar.gz
cd nginx-1.1.12
./configure --prefix=/home/nginx \
    --user=nginx \
    --group=nginx \
    --with-pcre=../library/pcre-8.21/ \
    --with-zlib=../library/zlib-1.2.5/
make
make install
cd ..
rm -rf nginx-1.1.12/
chown -R nginx:nginx *
sed -i 's/listen\s*80;/listen 8080;/g' conf/nginx.conf
export NGINX_HOME='/home/nginx/'
export NGINX_PID_FILE=$NGINX_HOME'logs/nginx.pid'

In case you encounter any problems, please refer to the short, but sufficient, official documentation. If it worked out for you, you can now use the following commands to start and stop the server as well as to reload the config.

# Start nginx (runs on port 8080)
su nginx -c $NGINX_HOME'sbin/nginx'

# Reload nginx config
kill -HUP $(cat $NGINX_PID_FILE)

# Stop nginx
kill -QUIT $(cat $NGINX_PID_FILE)

Check out the following blog if you need an init script for nginx.

That's me, Ben.
Hey, I am Ben Ripkens (bripkens) and this is my blog. I live in Düsseldorf (Germany) and I am employed by the codecentric AG as a Software Engineer. Web application frontends are my main area of expertise, but you may also find some other interesting articles on this blog.