zoukankan      html  css  js  c++  java
  • 003.安装nginx(lnmp)

    一.下载nginx

    下载nginx源码包,解压:

    [root@huh ~]# cd /usr/local/src/
    [root@huh src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
    [root@huh src]# tar zxvf nginx-1.6.2.tar.gz
    [root@huh src]# cd nginx-1.6.2

    二.安装nginx

    [root@huh nginx-1.6.2]# yum install -y pcre-devel
    [root@huh nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module
    [root@huh nginx-1.6.2]# make
    [root@huh nginx-1.6.2]# make install

    注:1.pcre是用来做正则的

      2.我们将ngnix安装在/usr/lcoal/nginx目录下

    三.启动nginx

    [root@huh nginx-1.6.2]# cd /usr/local/nginx/
    [root@huh nginx]# /usr/local/nginx/sbin/nginx 

     注:/usr/local/nginx/sbin/nginx可以启动nginx

     查看nginx进程和监听端口:

    [root@huh nginx]# ps aux |grep nginx
    root     18714  0.0  0.0   5000   628 ?        Ss   05:37   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    nobody   18715  0.0  0.0   5184   976 ?        S    05:37   0:00 nginx: worker process      
    root     18719  0.0  0.0   6048   784 pts/0    S+   05:41   0:00 grep --color nginx
    [root@huh nginx]# netstat -lnp |grep nginx
    tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      18714/nginx 

    四.nginx启动脚本

    nginx默认没有启动脚本,我们去写个:

    [root@huh nginx]# vim /etc/init.d/nginx

    写入内容:

    #!/bin/bash
    # chkconfig: - 30 21
    # description: http service.
    # Source Function Library
    . /etc/init.d/functions
    # Nginx Settings
    
    NGINX_SBIN="/usr/local/nginx/sbin/nginx"
    NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
    NGINX_PID="/usr/local/nginx/logs/nginx.pid"
    RETVAL=0
    prog="Nginx"
    
    start() {
            echo -n $"Starting $prog: "
            mkdir -p /dev/shm/nginx_temp
            daemon $NGINX_SBIN -c $NGINX_CONF
            RETVAL=$?
            echo
            return $RETVAL
    }
    
    stop() {
            echo -n $"Stopping $prog: "
            killproc -p $NGINX_PID $NGINX_SBIN -TERM
            rm -rf /dev/shm/nginx_temp
            RETVAL=$?
            echo
            return $RETVAL
    }
    
    reload(){
            echo -n $"Reloading $prog: "
            killproc -p $NGINX_PID $NGINX_SBIN -HUP
            RETVAL=$?
            echo
            return $RETVAL
    }
    
    restart(){
            stop
            start
    }
    
    configtest(){
        $NGINX_SBIN -c $NGINX_CONF -t
        return 0
    }
    
    case "$1" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      reload)
            reload
            ;;
      restart)
            restart
            ;;
      configtest)
            configtest
            ;;
      *)
            echo $"Usage: $0 {start|stop|reload|restart|configtest}"
            RETVAL=1
    esac
    
    exit $RETVAL

    五.设置为开机自启

    [root@huh nginx]# chmod 755 /etc/init.d/nginx 
    [root@huh nginx]# /etc/init.d/nginx stop
    停止 Nginx:                                               [确定]
    [root@huh nginx]# /etc/init.d/nginx start
    正在启动 Nginx:                                           [确定]
    [root@huh nginx]# chkconfig --add nginx
    [root@huh nginx]# chkconfig nginx on

  • 相关阅读:
    定义扩展点,实现发布订阅机制
    JS阻止事件冒泡
    Virtualbox安装黑苹果
    外部Tomcat使用Java热部署利器JRebel
    在Windows server 2016上使用docker
    Tomcat加载web.xml文件的顺序详解
    IDEA反编译整个jar包
    java集合类的继承结构
    利用BodyTagSupport创建带标签体的自定义标签
    jquery实现简单弹出框
  • 原文地址:https://www.cnblogs.com/ruo-yu/p/5167586.html
Copyright © 2011-2022 走看看