centos7.6安裝nginx並設置開機自啟


1、簡單安裝nginx-1.6版本

安裝依賴:

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

解壓下載的nginx-1.6

tar  -zxvf  nginx-1.16.1.tar.gz

安裝

cd   nginx-1.16.1

#安裝時--prefix 指定路徑,根據自己的需求來。

./configure --prefix=/www/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

make  && make install

安裝完成。

啟動nginx

cd   /www/server/nginx/sbin

執行    ./nginx    啟動 

           ./nginx  -s  stop  關閉

或者:/www/server/nginx/sbin/nginx

關閉nginx:/www/server/nginx/sbin/nginx   -s   stop

2、設置nginx開機自啟動

vim  /etc/init.d/nginx 

內容如下:

#! /bin/bash
# chkconfig: - 85 15
PATH=/www/server/nginx       ###這里是你安裝的路徑,替換成自己安裝的路徑
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/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() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || 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

3、加入系統設置開機自啟動

chmod +x /etc/rc.d/init.d/nginx (設置可執行權限)

chkconfig --add nginx (添加系統服務)

chkconfig --level 35 nginx on (開機自啟動)

可以使用systemctl   start nginx  啟動 

               systemctl   stop nginx   關閉


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM