Pages

Search result

Minggu, 19 Desember 2010

How to install nginx web server on CentOS

A few days ago I've been write article about "Migrate apache to nginx web server" and in this article I'll wrote about step by step how to installing nginx web server on CentOS. First, I've to install CentOS with a minimal package or removing all of option in Customize installation, disable selinux and firewall at moment. Now I'm ready to install dependencies and compile the nginx as web server.
Install some dependencies using YUM utilities:
yum install gcc gcc-c++ make automake openssl-devel mysql mysql-server mysql-devel pcre pcre-devel libtool-ltdl libtool-ltdl-devel libxml2 libxml2-devel libxml2-python gd gd-devel GeoIP-data GeoIP-devel GeoIP ImageMagick untar
And now download nginx file and extract, like this:
# cd /tmp
# wget http://nginx.org/download/nginx-0.8.54.tar.gz
# tar -zxvf nginx-0.8.54.tar.gz
# cd  ginx-0.8.54

To configure nginx before compile and installing on the system. By the way, I'm installing nginx to custom directory (/usr/local/nginx), see below:


# ./configure  --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx   --conf-path=/etc/nginx/nginx.conf   --error-log-path=/var/log/nginx/error.log   --pid-path=/var/run/nginx/nginx.pid    --lock-path=/var/lock/nginx.lock   --user=nginx   --group=nginx   --with-http_ssl_module   --with-http_flv_module   --with-http_gzip_static_module   --http-log-path=/var/log/nginx/access.log   --http-client-body-temp-path=/var/tmp/nginx/client/   --http-proxy-temp-path=/var/tmp/nginx/proxy/   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/   --with-http_degradation_module   --with-http_perl_module   --with-http_flv_module   --with-http_geoip_module    --with-http_gzip_static_module   --with-http_image_filter_module   --with-http_random_index_module   --with-http_realip_module   --with-http_secure_link_module   --with-http_ssl_module   --with-http_stub_status_module   --with-http_sub_module   --with-http_dav_module   --with-http_xslt_module --with-mail   --with-mail_ssl_module
And the compile and install the configuration:
# make
# make install

Now, nginx has already to install in the system and create the nginx init script, or by simple you should copy this script to /etc/init.d/nginx:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
Change nginx init script permission:
# chmod +x /etc/init.d/nginx

Try to start nginx and change to automatically run on runlevel 35:
# /etc/init.d/nginx start
# chkconfig --level 35 nginx on

To install php 5.3.xx read the next article :D, happy using nginx :D

Tidak ada komentar:

Posting Komentar