003.安裝nginx(lnmp)

一.下載nginxnginx

下載nginx源碼包,解壓:
vim

[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

 

二.安裝nginxbash

[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是用來作正則的tcp

  2.咱們將ngnix安裝在/usr/lcoal/nginx目錄下spa

 

三.啓動nginxrest

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

 注:/usr/local/nginx/sbin/nginx能夠啓動nginxcode

 查看nginx進程和監聽端口:regexp

[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啓動腳本blog

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

相關文章
相關標籤/搜索