zoukankan      html  css  js  c++  java
  • nginx安装

    NGINX的安装:
    查看是否挂载:
    list /mnt/
    挂载
    mount /dev/cdrom /mnt
    安装依赖:
    yum install gcc openssl-devel pcre-devel zlib-devel -y
    安装NGINX(解压压缩包)
    tar -zxf
    在解压目录内执行,并指定安装目录:
    ./configure --prefix=/usr/mydir/nginx
    编译:
    make
    安装(默认安装目录:usr/local/nginx)
    make install
    修改/etc/profile文件
    # export NGINX_HOME=/usr/local/nginx
    # export PATH=$PATH:$NGINX_HOME/sbin
    或 export PATH=$PATH:/usr/local/nginx/sbin
    生效:
    . /etc/profile 或 source /etc/profile
    添加安装的nginx到服务列表,将如下内容添加到/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="/opt/nginx/sbin/nginx"
    prog=$(basename $nginx)
     
    NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
     
    [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
     
    lockfile=/var/lock/subsys/nginx
     
    make_dirs() {
       # make required directories
       user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
       options=`$nginx -V 2>&1 | grep 'configure arguments:'`
       for opt in $options; do
           if [ `echo $opt | grep '.*-temp-path'` ]; then
               value=`echo $opt | cut -d "=" -f 2`
               if [ ! -d "$value" ]; then
                   # echo "creating" $value
                   mkdir -p $value && chown -R $user $value
               fi
           fi
       done
    }
     
    start() {
        [ -x $nginx ] || exit 5
        [ -f $NGINX_CONF_FILE ] || exit 6
        make_dirs
        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
        sleep 1
        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
    修改执行权限
    chmod +x nginx
    添加该文件到系统服务中去
    chkconfig --add nginx
    查看服务情况:
    chkconfig
    让NGINX的服务三选项打开
    chkconfig --level 3 nginx on
    服务的启动停止
    service nginx start|stop|reload
    设置开机启动
    chkconfig nginx on
     
    nginx的403权限问题:
    修改访问目录的权限为755
      找到Nginx的配置文件nginx.conf,做如下改变:
      (1)将user nobody; 改为user root;
      (2)找到 autoindex  off 更改为on(Nginx默认是不支持浏览目录的)

  • 相关阅读:
    prometheus基础概念
    Prometheus告警处理
    什么是prometheus?
    Prometheus的PromQL
    Prometheus的Exporter详解
    leetcode unique path I&&II
    leetcode Palindrome Partitioning
    leetcode 最大子矩阵(5星推荐)
    leetcode Sum Root to Leaf Numbers 二叉树所有叶节点的路径和
    leetcode Spiral Matrix I
  • 原文地址:https://www.cnblogs.com/hhz-97/p/14027460.html
Copyright © 2011-2022 走看看