nginx--service配置

nginx从今天开始进行相关学习了,包括:1、注册centos的service服务;2、相关的tomcat负载;3、https配置;4、session共享配置

1、注册centos的service服务

[root@localhost /]# cd /etc/init.d/
[root@localhost init.d]# vim nginx

#!/bin/sh
#chkconfig:
# 表示在2345模式下,开机自启动
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem. nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=
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
[ -x $nginxd ] || exit # Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit
esac
exit $RETVAL

给添加权限

chmod a+x /etc/init.d/nginx

将nginx加入到,开启自启动项

chkconfig --add nginx
chkconfig nginx on

测试

[root@localhost init.d]# service nginx start
Starting nginx: [ OK ]
[root@localhost init.d]# service nginx stop
Stopping nginx: [ OK ]
[root@localhost init.d]# service nginx start
Starting nginx: [ OK ]
[root@localhost init.d]# service nginx reload
Reloading nginx: [ OK ]

我这里的环境是centos6.4如果是7以上还需要配置一些其他,这里不写了,可以网上找一下

下一篇配置一下tomcat

上一篇:Django中,ajax检测注册用户信息是否可用?


下一篇:Linux上分析java程序的问题