CentOS5.5 Nginx环境搭建(源码方式安装)
CentOS5.5 Nginx环境搭建有几个程序库要先安装:
1、GCC,GCC-C++
2、Zlib
3、pcre
4、openssl
详细安装步骤如下:
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
wget http://mirrors.163.com/.help/CentOS-Base-163.repo
mv CentOS-Base-163.repo CentOS-Base.repo
yum makecache
mkdir -p /home/software
cd /home/software
一、GCC
可以直接用yum来安装
yum -y install gcc
yum -y install gcc-c++
二、Zlib安装
下载地址:http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download
cd /home/software
wget http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download
tar zxvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure
make
make install
三、pcre安装
下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
cd /home/software
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
tar zxvf pcre-8.30.tar.gz
cd pcre-8.30
./configure
make
make install
四、openssl安装
下载地址:http://www.openssl.org/source/openssl-1.0.0g.tar.gz
cd /home/software
wget http://www.openssl.org/source/openssl-1.0.0g.tar.gz
tar zxvf openssl-1.0.0g.tar.gz
cd openssl-1.0.0g
./config --prefix=/usr/local/ --openssldir=/usr/local/openssl-1.0.0g shared zlib-dynamic enable-camellia enable-tlsext
make
make install
五、nginx安装
下载地址:http://nginx.org/download/nginx-1.0.13.tar.gz
cd /home/software
wget http://nginx.org/download/nginx-1.0.13.tar.gz
tar zxvf nginx-1.0.13.tar.gz
cd nginx-1.0.13
./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/share \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/log/run/nginx.pid \
--lock-path=/var/log/lock/subsys/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \
--with-mail_ssl_module
make
make install
为Nginx建立用户
groupadd -f nginx useradd -g nginx nginx
创建运行脚本
vi /etc/init.d/nginx
#! /bin/bash
# Startup script for the Nginx HTTP Server
# chkconfig: - 85 15
# description: Startup script for the Nginx HTTP Server
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx-0.8/conf/nginx.conf
nginxd=/usr/sbin/nginx
nginx_config=/etc/nginx/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/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 $nginx_pid
}
# reload nginx service functions.
reload() {
echo -n "Reloading $prog: "
killproc $nginxd -HUP
RETVAL=$?
echo
[ $RETVAL = 0 ]
}
# 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
启动nginx
/etc/init.d/nginx restart
设置自启动
chkconfig nginx on

浙公网安备 33010602011771号