zoukankan      html  css  js  c++  java
  • tony_nginx的安装和配置

    yum安装nginx

    Centos默认的yum源里没有nginx,需要手动添加源,有两种方法:

    使用nginx提供的一个源设置安装包

    nginx下载页面:http://nginx.org/en/download.html

    nginx提供4个版本的系统的源:

    我选择Centos6,文件名为:nginx-release-centos-6-0.el6.ngx.noarch.rpm。

    在服务器上安装:

    rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

    之后便可以使用yum快速安装了:

    yum install nginx

    手动添加nginx源

    cd /etc/yum.repos.d
    
    vim nginx.repo
    
    #内容为:
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/6/$basearch/
    gpgcheck=0
    enabled=1

    baseurl中centos和6可以更改为自己的版本,比如redhat 5版本的链接为:

    baseurl=http://nginx.org/packages/rhel/5/$basearch/

    详情可以自己看nginx的下载页面,包括其他系统的源安装方法。

    相关路径

    nginx可执行文件:/usr/sbin/nginx

    nginx配置目录:/etc/nginx

    nginx log目录:/var/log/nginx

    编译安装nginx

    我的nginx编译安装代码:

    yum install perl-ExtUtils-Embed.x86_64 pcre-devel.x86_64
    #根据自己的需求,选择参数,可用的参数可以使用./configure --help命令查看
    ./configure --prefix=/opt/nginx
                     --with-http_gzip_static_module 
                     --with-http_perl_module
                     --with-pcre 
                     --with- rtsig_module 
                     --with-select_module 
                     --with-poll_module 
                     --with-file-aio
    
    make
    make install

    为编译安装的nginx配置init脚本:

    vim /etc/init.d/nginx
    #内容取自yum安装的nginx后,生成的文件,改下里面的路径即可使用了
    #!/bin/sh
    #
    # nginx        Startup script for nginx
    #
    # chkconfig: - 85 15
    # processname: nginx
    # config: /opt/nginx/conf/nginx.conf
    # config: /etc/sysconfig/nginx
    # pidfile: /opt/nginx/logs/nginx.pid
    # description: nginx is a HTTP and reverse proxy server
    #
    ### BEGIN INIT INFO
    # Provides: nginx
    # Required-Start: $local_fs $remote_fs $network
    # Required-Stop: $local_fs $remote_fs $network
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: start and stop nginx
    ### END INIT INFO
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    if [ -f /etc/sysconfig/nginx ]; then
        . /etc/sysconfig/nginx
    fi
    
    prog=nginx
    nginx=${NGINX-/opt/nginx/sbin/nginx}
    conffile=${CONFFILE-/opt/nginx/conf/nginx.conf}
    lockfile=${LOCKFILE-/var/lock/subsys/nginx}
    pidfile=${PIDFILE-/opt/nginx/logs/nginx.pid}
    SLEEPMSEC=100000
    RETVAL=0
    
    start() {
        echo -n $"Starting $prog: "
    
        daemon --pidfile=${pidfile} ${nginx} -c ${conffile}
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
    }
    
    stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} ${prog}
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    }
    
    reload() {
        echo -n $"Reloading $prog: "
        killproc -p ${pidfile} ${prog} -HUP
        RETVAL=$?
        echo
    }
    
    upgrade() {
        oldbinpidfile=${pidfile}.oldbin
    
        configtest -q || return 6
        echo -n $"Staring new master $prog: "
        killproc -p ${pidfile} ${prog} -USR2
        RETVAL=$?
        echo
        /bin/usleep $SLEEPMSEC
        if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then
            echo -n $"Graceful shutdown of old $prog: "
            killproc -p ${oldbinpidfile} ${prog} -QUIT
            RETVAL=$?
            echo 
        else
            echo $"Upgrade failed!"
            return 1
        fi
    }
    
    configtest() {
        if [ "$#" -ne 0 ] ; then
            case "$1" in
                -q)
                    FLAG=$1
                    ;;
                *)
                    ;;
            esac
            shift
        fi
        ${nginx} -t -c ${conffile} $FLAG
        RETVAL=$?
        return $RETVAL
    }
    
    rh_status() {
        status -p ${pidfile} ${nginx}
    }
    
    # See how we were called.
    case "$1" in
        start)
            rh_status >/dev/null 2>&1 && exit 0
            start
            ;;
        stop)
            stop
            ;;
        status)
            rh_status
            RETVAL=$?
            ;;
        restart)
            configtest -q || exit $RETVAL
            stop
            start
            ;;
        upgrade)
            upgrade
            ;;
        condrestart|try-restart)
            if rh_status >/dev/null 2>&1; then
                stop
                start
            fi
            ;;
        force-reload|reload)
            reload
            ;;
        configtest)
            configtest
            ;;
        *)
            echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
            RETVAL=2
    esac
    
    exit $RETVAL

    使用chkconfig安装为安装启动项

    chkconfig --add nginx
    chkconfig nginx on

    nginx命令:
    启动:nginx
    停止:nginx -s stop
    重置生效:nginx -s reload


  • 相关阅读:
    python爬虫之Anaconda安装
    python爬虫之scrapy安装(一)
    python爬虫之redis环境简单部署
    python爬虫之Phantomjs安装和使用
    python爬虫之win7Mongod安装使用
    python爬虫之PyQuery的基本使用
    python爬虫之xpath的基本使用
    python爬虫之git的使用(windows下pycharm使用)
    Sass教程
    Vue.js教程—1.介绍和安装
  • 原文地址:https://www.cnblogs.com/tonykan/p/3523674.html
Copyright © 2011-2022 走看看