CentOS 6.2 安装Nginx并设置为开机服务[服务器安全]
本文“CentOS 6.2 安装Nginx并设置为开机服务[服务器安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
环境预备工作:
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
1 最简单安装方法:
yum install nginx
下载 nginx
wget http://nginx.org/download/nginx-1.0.2.tar.gz
解压
tar –xzvf nginx-1.0.2.tar.gz
cd nginx-1.0.2
./configure
configure 支持下面的选项:
--prefix=
--sbin-path=
--conf-path=
--pid-path=
--lock-path=
--error-log-path=
--http-log-path=
--user=
--group=
--builddir=DIR - 指定编译的目录
--with-rtsig_module - 启用 rtsig 模块最后安装
make && make install
启动nginx
进入安装目录sbin下:
./nginx
查看nginx进程:
ps –ef | grep nginx
设置成系统开机服务:
在 /etc/init.d/ 目录下成立 nginx 文件 内容以下:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by gcec at 2009.10.22.
# it is v.0.0.1 version.
# if you find any errors on this scripts,please contact gcec cyz.
# and send mail to support at gcec dot cc.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/app/nginx/sbin/nginx
nginx_config=/app/nginx/conf/nginx.conf
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
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && 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 1
esac
exit $RETVAL
chkconfig --add nginx
chkconfig --level 345 nginx on
chkconfig --list nginx
启动
service nginx start
终止
service nginx stop
以上是“CentOS 6.2 安装Nginx并设置为开机服务[服务器安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |