linux下安装nginx

       nginx是一款轻量级,很强大的http服务器,经常被用于负载均衡。现在简单说明在linux如何安装nginx

  • nginx下载解压

             http:nginx.org 下载

  • nginx依赖包

              pcre

              openssl

              gzip


             进行在线升级

yum -y install pcre-devel;

yum -y install openssl;

yum -y install openssl-devel;  
  • nginx安装

             指定安装路径为 /usr/local/nginx

            

./configure --prefix=/usr/local/nginx
make 
make install
make clean


  • nginx自启动脚本

 

    #!/bin/bash
    nginxd=/usr/local/nginx/sbin/nginx
    nginx_config=/usr/local/nginx/conf/nginx.conf
    nginx_pid=/usr/local/nginx/logs/nginx.pid

    RETVAL=0
    prog="nginx"

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

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

    # Check that networking is up.

    [ ${NETWORKING} = "no" ] && exit 0
    [ -x $nginxd ] || exit 0

    # Start nginx daemons functions.

    start() {
    if [ -e $nginx_pid ];then
       echo "nginx already running...."
       exit 1
    fi
       echo -n $"Starting $prog: "
       daemon $nginxd -c ${nginx_config}
       RETVAL=$?
       echo
       [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
       return $RETVAL
    }

    # Stop nginx daemons functions.

    stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
    }

    # reload nginx service functions.

    reload() {
        echo -n $"Reloading $prog: "
        #kill -HUP `cat ${nginx_pid}`
        killproc $nginxd -HUP
        RETVAL=$?
        echo
    }

    # See how we were called.

    case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    reload)
        reload
        ;;
    restart)
        stop
        start
        ;;
    status)
        status $prog
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
    esac
    exit $RETVAL


 

  • nginx测试

             输入http:ip 如果显示welcome nginx ,说明安装成功

 

posted @ 2014-09-23 11:14  wala-wo  阅读(200)  评论(0编辑  收藏  举报