码迷,mamicode.com
首页 > 其他好文 > 详细

003.安装nginx(lnmp)

时间:2016-01-28 23:59:51      阅读:399      评论:0      收藏:0      [点我收藏+]

标签:

一.下载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
[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

003.安装nginx(lnmp)

标签:

原文地址:http://www.cnblogs.com/ruo-yu/p/5167586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!