小知识:Linux下创建nginx脚本-start、stop、reload…

1、关闭nginx

利用ps -aux | grep nginx 查看nginx是否启动 如果启动了就kill杀死

2、创建/etc/init.d/nginx文件
?
1
root@dnnp:~/software/nginx-1.2.3# vim /etc/init.d/nginx

3、添加权限并启动

?
1
2
3
4
5
6
7
8
9
root@dnnp:~/software/nginx-1.2.3# chmod +x /etc/init.d/nginx
root@dnnp:~/software/nginx-1.2.3# /etc/init.d/nginx start
Starting nginx: nginx.
root@dnnp:~/software/nginx-1.2.3# ps -aux | grep nginx
Warning: bad ps syntax, perhaps a bogus -? See http://procps.sf.net/faq.html
root   25078 0.0 0.0  4596  700 ?    Ss  14:20  0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody  25079 0.0 0.1  4820 1056 ?    S  14:20  0:00 nginx: worker process
root   25081 0.0 0.0  3304  768 pts/0  S+  14:20  0:00 grep nginx
root@dnnp:~/software/nginx-1.2.3#

注:/etc/init.d/nginx文件内容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /bin/sh
### BEGIN INIT INFO
# Provides:     nginx
# Required-Start:  $all
# Required-Stop:   $all
# Default-Start:   2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: starts the nginx web server
# Description:    starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
#    . /usr/local/nginx/conf
fi
set -e
. /lib/lsb/init-functions
case “$1” in
start)
echo -n “Starting $DESC: “
start-stop-daemon –start –quiet –pidfile /usr/local/nginx/logs/$NAME.pid \
–exec $DAEMON — $DAEMON_OPTS || true
echo “$NAME.”
;;
stop)
echo -n “Stopping $DESC: “
start-stop-daemon –stop –quiet –pidfile /usr/local/nginx/logs/$NAME.pid \
–exec $DAEMON || true
echo “$NAME.”
;;
restart|force-reload)
echo -n “Restarting $DESC: “
start-stop-daemon –stop –quiet –pidfile \
/usr/local/nginx/logs/$NAME.pid –exec $DAEMON || true
sleep 1
start-stop-daemon –start –quiet –pidfile \
/usr/local/nginx/logs/$NAME.pid –exec $DAEMON — $DAEMON_OPTS || true
echo “$NAME.”
;;
reload)
echo -n “Reloading $DESC configuration: “
start-stop-daemon –stop –signal HUP –quiet –pidfile /usr/local/nginx/logs/$NAME.pid \
–exec $DAEMON || true
echo “$NAME.”
;;
status)
status_of_proc -p /usr/local/nginx/logs/$NAME.pid “$DAEMON” nginx && exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo “Usage: $N {start|stop|restart|reload|force-reload|status}” >&2
exit 1
;;
esac
exit 0
声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:nginx中使用nginx-http-concat模块合并静态资源文件

2023-5-9 3:50:32

建站知识

小知识:nginx:413 Request Entity Too Large的处理办法--修改 PHP上传文件大小

2023-5-9 4:00:03

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索