zoukankan      html  css  js  c++  java
  • nginx

    一、安装nginx时必须先安装相应的编译工具
    yum -y install gcc gcc-c++ autoconf automake
    yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

    建立nginx 组
    groupadd -r nginx
    useradd -s /sbin/nologin -g nginx -r nginx
    id nginx

    zlib:nginx提供gzip模块,需要zlib库支持
    openssl:nginx提供ssl功能
    pcre:支持地址重写rewrite功能

    二、tar -zxvf nginx-1.2.8.tar.gz

    三、cd nginx-1.2.8

    四、./configure
    --prefix=/usr
    --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
    --user=nginx
    --group=nginx 

    五、make && make install


    小结:centos没有安装make编译器
    解决:yum -y install gcc automake autoconf libtool make

    六、在/etc/init.d/目录下编写脚本,名为nginx

    #!/bin/sh
    #
    # nginx - this script starts and stops the nginx daemon
    #
    # chkconfig:   - 85 15
    # description:  Nginx is an HTTP(S) server, HTTP(S) reverse 
    #               proxy and IMAP/POP3 proxy server
    # processname: nginx
    # config:      /etc/nginx/nginx.conf
    # config:      /etc/sysconfig/nginx
    # pidfile:     /var/run/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)
    
    sysconfig="/etc/sysconfig/$prog"
    lockfile="/var/lock/subsys/nginx"
    pidfile="/var/run/${prog}.pid"
    
    NGINX_CONF_FILE="/etc/nginx/nginx.conf"
    
    [ -f $sysconfig ] && . $sysconfig
    
    
    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 -p $pidfile $prog
        retval=$?
        echo
        [ $retval -eq 0 ] && rm -f $lockfile
        return $retval
    }
    
    restart() {
        configtest_q || return 6
        stop
        start
    }
    
    reload() {
        configtest_q || return 6
        echo -n $"Reloading $prog: "
        killproc -p $pidfile $prog -HUP
        echo
    }
    
    configtest() {
        $nginx -t -c $NGINX_CONF_FILE
    }
    
    configtest_q() {
        $nginx -t -q -c $NGINX_CONF_FILE
    }
    
    rh_status() {
        status $prog
    }
    
    rh_status_q() {
        rh_status >/dev/null 2>&1
    }
    
    # Upgrade the binary with no downtime.
    upgrade() {
        local oldbin_pidfile="${pidfile}.oldbin"
    
        configtest_q || return 6
        echo -n $"Upgrading $prog: "
        killproc -p $pidfile $prog -USR2
        retval=$?
        sleep 1
        if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
            killproc -p $oldbin_pidfile $prog -QUIT
            success $"$prog online upgrade"
            echo 
            return 0
        else
            failure $"$prog online upgrade"
            echo
            return 1
        fi
    }
    
    # Tell nginx to reopen logs
    reopen_logs() {
        configtest_q || return 6
        echo -n $"Reopening $prog logs: "
        killproc -p $pidfile $prog -USR1
        retval=$?
        echo
        return $retval
    }
    
    case "$1" in
        start)
            rh_status_q && exit 0
            $1
            ;;
        stop)
            rh_status_q || exit 0
            $1
            ;;
        restart|configtest|reopen_logs)
            $1
            ;;
        force-reload|upgrade) 
            rh_status_q || exit 7
            upgrade
            ;;
        reload)
            rh_status_q || exit 7
            $1
            ;;
        status|status_q)
            rh_$1
            ;;
        condrestart|try-restart)
            rh_status_q || exit 7
            restart
    	    ;;
        *)
            echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
            exit 2
    esac
    

      

    [root@example ~]# cp nginx /etc/init.d/
    [root@example ~]# chmod 755 /etc/init.d/nginx
    [root@example ~]# chkconfig --add nginx

  • 相关阅读:
    java基础面试题(一)
    关于Redis的十个高频面试问题
    postgres中的merge join
    cgdb调试postgresql
    再见了,程序员!
    掌握这个小技巧,让你的 C++ 编译速度提升 50 倍!
    C语言修仙大法!基础知识全复习(纯干货)!!!
    一锅端了!北京朝阳一互联网公司被端,警方上门,23人被带走…
    C++入口不是main?知乎上都快打起来了,你们不要再打了啦!
    不用创建项目,直接在 VS 里快速测试 C/C++ 代码 !
  • 原文地址:https://www.cnblogs.com/nowphp/p/6883259.html
Copyright © 2011-2022 走看看