1、关闭nginx
利用ps -aux | grep nginx 查看nginx是否启动 如果启动了就kill杀死
2、创建/etc/init.d/nginx文件
1 |
root@dnnp:~/software/nginx-1.2.3 |
3、添加权限并启动
1 |
root@dnnp:~/software/nginx-1.2.3 |
2 |
root@dnnp:~/software/nginx-1.2.3 |
4 |
root@dnnp:~/software/nginx-1.2.3 |
6 |
root 25078 0.0 0.0 4596 700 ? Ss 14:20 0:00 nginx: master process /usr/ local /nginx/sbin/nginx |
7 |
nobody 25079 0.0 0.1 4820 1056 ? S 14:20 0:00 nginx: worker process |
8 |
root 25081 0.0 0.0 3304 768 pts/0 S+ 14:20 0:00 grep nginx |
9 |
root@dnnp:~/software/nginx-1.2.3 |
注:/etc/init.d/nginx文件内容如下
13 |
PATH=/usr/ local /sbin:/usr/ local /bin:/sbin:/bin:/usr/sbin:/usr/bin |
14 |
DAEMON=/usr/ local /nginx/sbin/nginx |
18 |
test -x $DAEMON || exit 0 |
21 |
if [ -f /etc/default/nginx ] ; then |
28 |
. /lib/lsb/init-functions |
32 |
echo -n "Starting $DESC: " |
33 |
start-stop-daemon --start --quiet --pidfile /usr/ local /nginx/logs/$NAME.pid \ |
34 |
-- exec $DAEMON -- $DAEMON_OPTS || true |
38 |
echo -n "Stopping $DESC: " |
39 |
start-stop-daemon --stop --quiet --pidfile /usr/ local /nginx/logs/$NAME.pid \ |
40 |
-- exec $DAEMON || true |
44 |
echo -n "Restarting $DESC: " |
45 |
start-stop-daemon --stop --quiet --pidfile \ |
46 |
/usr/ local /nginx/logs/$NAME.pid -- exec $DAEMON || true |
48 |
start-stop-daemon --start --quiet --pidfile \ |
49 |
/usr/ local /nginx/logs/$NAME.pid -- exec $DAEMON -- $DAEMON_OPTS || true |
53 |
echo -n "Reloading $DESC configuration: " |
54 |
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/ local /nginx/logs/$NAME.pid \ |
55 |
-- exec $DAEMON || true |
59 |
status_of_proc -p /usr/ local /nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $? |
63 |
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 |