• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

Centos7 nginx的安装以及开机自启动的设置

Nginx相关 zbjtwyyue 98次浏览 已收录 0个评论

安装nginx对应的软件
yum -y install pcre pcre-devel
yum -y install openssl-devel openssl
yum -y install gcc-c++
安装软件
mkdir -p /home/tools #用于存放nginx-1.6.3.tar.gz
useradd www -s /sbin/nologin -M
cd /home/tools
wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
tar xf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure –user=www –group=www –with-http_stub_status_module –with-http_ssl_module –prefix=/application/nginx-1.6.3
make
make install
ln -s /application/nginx-1.6.3/ /application/nginx
/application/nginx/sbin/nginx #启动
ps -ef |grep nginx #检查有无启动成功
加入开机自启动
编辑下面文件
vim /etc/init.d/nginx
#!/bin/sh
#chkconfig: 2345 80 90  

description: Start and Stop nginx

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DESC="nginx daemon"
    NAME=nginx
    DAEMON=*/application/nginx*/sbin/$NAME
    CONFIGFILE=*/application/nginx/*conf/$NAME.conf
    PIDFILE=*/application/nginx*/logs/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME

    set -e
    [ -x "$DAEMON" ] || exit 0

    do_start() {
    $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
    }

    do_stop() {
    kill -INT `cat $PIDFILE` || echo -n "nginx not running"
    }

    do_reload() {
    kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
    }
    case "$1" in
    start)
    echo -n "Starting $DESC: $NAME"
    do_start
    echo "."
    ;;
    stop)
    echo -n "Stopping $DESC: $NAME"
    do_stop
    echo "."
    ;;
    reload|graceful)
    echo -n "Reloading $DESC configuration..."
    do_reload
    echo "."
    ;;
    restart)
    echo -n "Restarting $DESC: $NAME"
    do_stop
    do_start
    echo "."
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
    exit 3
    ;;
    esac
    exit 0

只需要将该内容/application/nginx换成对应的安装目录即可

改变其权限:
    chmod +x /etc/init.d/nginx
    service nginx stop
    chkconfig --add nginx
    chkconfig nginx on
    service nginx start
重启之后查看是否加入开机自启动``
    ps -ef |grep nginx

VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明Centos7 nginx的安装以及开机自启动的设置
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址