手动安装安装完Nginx,如果需要下次开机自动启动还需要写一个简单脚步,以下为具体步骤(默认root用户操作,非root用户 部分指令禁止操作)
在 /etc/init.d/目录下新建一个Nginx脚本文件
执行指令 vi/etc/init.d/Nginx 写好脚本后,:wq保存退出
切换到/etc/init.d/下
执行 ./Nginx start
执行 ps -ef|grep Nginx 查看进程是否存在,显示以为内容说明启动成功
root 1502 1 0 14:06 ? 00:00:00 Nginx: master process /usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf
nobody 1503 1502 0 14:06 ? 00:00:00 Nginx: worker process
以下为Nginx脚步内容 脚本头部的变量可能因系统的不同需要修改
#! /bin/sh
PATH=/usr/local/Nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DESC="Nginx daemon" NAME=Nginx DAEMON=/usr/local/Nginx/sbin/$NAME CONFIGFILE=/usr/local/Nginx/conf/$NAME.conf PIDFILE=/usr/local/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() { if [ -f "$PIDFILE" ]; then kill -INT `cat $PIDFILE` || echo -n "Nginx not running" fi } 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