CentOS-6.5安装配置Nginx

1.安装前提

下载nginx,这里下载的目前最新版本:nginx-1.7.12.tar.gz

在安装nginx前,需先安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。

#yum -y install gcc gcc-c++ make autoconf automake libtool

#yum -y install  zlib zlib-devel openssl openssl--devel pcre pcre-devel

检查系统是否已安装过nginx

#rpm -qa |grep nginx  (find / -name nginx)

如有安装,卸载

#yum remove nginx

2.安装nginx

#cd /usr/local

# tar -zxvf nginx-1.7.12.tar.gz

#rm -rf nginx-1.7.12.tar.gz

#cd /usr/local/nginx-1.7.12

#./configure --prefix=/usr/local/nginx

#make && make install

3.设置开机启动

新建自启动脚本

vi /etc/init.d/nginx

#!/bin/bash
#
#kconfig:345 85 15
#description:nginxisaWorldWideWebserver.Itisusedtoserve
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginx ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginx -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
     echo -n $"Stopping $prog: "
     killproc $nginx
     RETVAL=$?
     echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

#chmod +x /etc/init.d/nginx

添加为系统服务,开机自动启动

#chkconfig --addnginx

#chkconfig nginx on

#service nginx start|restart|stop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值