1.准备各种源代码
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-1.6.tar.gz
wget http://nginx.org/download/nginx-1.3.5.tar.gz
2.编译安装
1.安装pcre
tar -zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure --prefix=/usr/local/pcre
make
make install
2.安装nginx
tar -zxvf ngx_cache_purge-1.6.tar.gz
mv ngx_cache_purge-1.6 /usr/local/ngx_cache_purge
tar -zxvf nginx-1.3.5.tar.gz
cd nginx-1.3.5
./configure --prefix=/usr/local/nginx --user=nobody --group=nobody --with-http_stub_status_module --with-openssl=/usr/include/openssl --with-pcre=/tmp/pcre-8.31 --add-module=/usr/local/ngx_cache_purge --with-http_gzip_static_module
# 注意:--with-pcre指向的是源码包解压的路径,而不是安装的路径,否则编译会报错
make
make install
chown -R nobody:nobody /usr/local/nginx/html/
3.设置nginx开机启动
vi /etc/rc.d/init.d/nginx
tar -zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure --prefix=/usr/local/pcre
make
make install
2.安装nginx
tar -zxvf ngx_cache_purge-1.6.tar.gz
mv ngx_cache_purge-1.6 /usr/local/ngx_cache_purge
tar -zxvf nginx-1.3.5.tar.gz
cd nginx-1.3.5
./configure --prefix=/usr/local/nginx --user=nobody --group=nobody --with-http_stub_status_module --with-openssl=/usr/include/openssl --with-pcre=/tmp/pcre-8.31 --add-module=/usr/local/ngx_cache_purge --with-http_gzip_static_module
# 注意:--with-pcre指向的是源码包解压的路径,而不是安装的路径,否则编译会报错
make
make install
chown -R nobody:nobody /usr/local/nginx/html/
3.设置nginx开机启动
vi /etc/rc.d/init.d/nginx
#!/bin/bash
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/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 /usr/local/nginx/logs/nginx.pid
}
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
;;
原作者: http://andyxu.blog.51cto.com/2050315/975413