开机自启动nginx
这里使用的是编写shell脚本的方式来处理
vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
#nginx程序路径
nginxd=/usr/local/nginx/sbin/nginx
#nginx配置文件路径
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx pid文件的路径,可以在nginx的配置文件中找到
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
fi
}
# Stop nginx daemons functions.
stop() {
}
# reload nginx service functions.
reload() {
}
# See how we were called.
case "$1" in
start)
stop)
reload)
restart)
status)
*)
esac
exit $RETVAL
:wq
设置文件的访问权限
chmod a+x /etc/init.d/nginx
这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx
同样的修改了nginx的配置文件nginx.conf,也可以使用上面的命令重新加载新的配置文件并运行,可以将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了
vi /etc/rc.local
加入一行
将nginx添加为系统服务
chkconfig --add nginx
chkconfig nginx on
# chkconfig: - 85 15 必须写