nginx环境搭建

本文提供了一份详细的指南,介绍了如何通过编译安装的方式部署Nginx及pcre依赖库。内容覆盖了从下载源代码到配置开机启动的全过程,并特别强调了--with-pcre参数正确使用的注意事项。

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
#!/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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值