1 进入到安装的目录里面 whereis nginx
2. 进入该路径:cd /usr/local/nginx/sbin
3 启动nginx 命令: ./nginx 出现下面启动成功
4 查看nginx 的状态 ps -ef | grep nginx 出现master 则启动成功
5 关闭nginx 命令 kill -9 8725(进程号 上面的) 则关闭nginx
6. 停止 nginx 命令: ./nginx -s stop
7.重启nginx命令:./nginx -s reload
第一步
检查nginx运行得进程
(proenv) [root@TXMaster init.d]# ps -ef | grep -i nginx
root 2996 1 0 14:49 ? 00:00:00 nginx: master process ./nginx
nginx 2997 2996 0 14:49 ? 00:00:00 nginx: worker process
root 10247 2937 0 15:33 pts/0 00:00:00 grep --color=auto -i nginx
关闭nginx
(proenv) [root@TXMaster init.d]# kill 9 2996
(proenv) [root@TXMaster init.d]# kill 9 2997
bash: kill: (2997) - No such process
(proenv) [root@TXMaster init.d]#
(proenv) [root@TXMaster init.d]# ps -ef | grep -i nginx
root 10374 2937 0 15:34 pts/0 00:00:00 grep --color=auto -i nginx
(proenv) [root@TXMaster init.d]#
创建nginx配置文件
(proenv) [root@TXMaster init.d]# vi /etc/init.d/nginx
#!/bin/bash
nginx - this script starts and stops the nginx daemon
chkconfig: - 85 15
description: Nginx is an HTTP(S) server, HTTP(S) reverse \
proxy and IMAP/POP3 proxy server
processname: nginx
config: /usr/local/nginx/conf/nginx.conf
pidfile: /usr/local/nginx/logs/nginx.pid
Source function library.
. /etc/rc.d/init.d/functions
Source networking configuration.
. /etc/sysconfig/network
Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c
N
G
I
N
X
C
O
N
F
F
I
L
E
r
e
t
v
a
l
=
NGINX_CONF_FILE retval=
NGINXCONFFILEretval=?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc
p
r
o
g
−
Q
U
I
T
r
e
t
v
a
l
=
prog -QUIT retval=
prog−QUITretval=?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc
n
g
i
n
x
−
H
U
P
R
E
T
V
A
L
=
nginx -HUP RETVAL=
nginx−HUPRETVAL=?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case “$1” in
start)
rh_status_q && exit 0
start
;;
stop)
rh_status_q || exit 0
stop
;;
restart|configtest)
restart
;;
reload)
rh_status_q || exit 7
reload
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
;;
保存退出
第三步
修改文件权限
(proenv) [root@TXMaster init.d]# chmod +x /etc/init.d/nginx
第四步
(proenv) [root@TXMaster init.d]# /sbin/chkconfig nginx on
Note: Forwarding request to ‘systemctl enable nginx.service’.
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
检查一下
(proenv) [root@TXMaster init.d]# /sbin/chkconfig --list nginx
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use ‘systemctl list-unit-files’.
To see services enabled on particular target use
‘systemctl list-dependencies [target]’.
service nginx supports chkconfig, but is not referenced in any runlevel (run ‘chkconfig --add nginx’)
完成!
启动Nginx服务
(proenv) [root@TXMaster init.d]# service nginx start
Starting nginx (via systemctl): [ OK ]
(proenv) [root@TXMaster init.d]# service nginx restart
Restarting nginx (via systemctl): [ OK ]
(proenv) [root@TXMaster init.d]# /etc/init.d/nginx status
/etc/init.d/nginx: line 106: syntax error: unexpected end of file
(proenv) [root@TXMaster init.d]#
之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload
service nginx status
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
/etc/init.d/nginx status