在CentOS下安装nginx

1 nginx安装步骤

1.1 安装开发组件

yum install pcre-devel -y 依赖perl扩展的正则表达式
yum install openssl-devel -y
yum install gd-devel -y gd库是图片过滤处理模块
yum install gcc -y C、C++编译器
groupadd -r -g 110 nginx 添加以个nginx组为系统组
useradd -r -u 110 -g 110 nginx 添加以个用户为系统用户,专门管理nginx

1.2 下载nginx解压并安装

cd /usr/local/src
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar xf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure
make
make install

1.3 制作启动脚本

cd /etc/init.d
cat > nginx
复制以下脚本
#!/bin/sh
# config: /usr/local/nginx/conf/nginx.conf

nginx_path=”/usr/local/nginx”
nginx_pid=”/var/run/nginx/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

[ -xnginx_path/sbin/nginx ] || exit 0

RETVAL=0
prog=”nginx”

start() {
# Start daemons.

if [ -e nginx_pid -a ! -znginx_pid ];then
echo “nginx already running….”
exit 1
fi
if [ -e nginx_path/conf/nginx.conf ];then
echo -n
“Starting prog: “nginx_path/sbin/nginx -c nginx_path/conf/nginx.conf &
RETVAL=
?
[ RETVAL -eq 0 ] && {
touch /var/lock/subsys/
prog
success prog”
}
echo
else
RETVAL=1
fi
return RETVAL
}

# Stop daemons.
stop() {
echo -n“Stopping prog: ”
killproc -d 10
nigx_path/sbin/nginx
RETVAL=?
echo
[
RETVAL = 0 ] && rm -f nginx_pid /var/lock/subsys/prog
}

# See how we were called.
case “1″ in
start)
start
;;

stop)
stop
;;

reconfigure)
stop
start
;;

status)
statusprog
RETVAL=?
;;

*)
echo“Usage: 0 {start|stop|reconfigure|status}”
exit 1
esac

exitRETVAL
粘贴以上脚本
按下CTRL+C
chmod 755 nginx
service nginx start
service iptables stop
chkconfig –add nginx

nginx安装完成