天天看點

nginx源碼編譯

1、nginx 的編譯
 編譯前的環境準備:
# yum groupinstall  "Desktop Platform Development" "Development tools" -y
# yum  install zlib zlib-devel openssl openssl-devel pcre-devel geoip-devel -y 
子產品解決方案:
 1)報錯提示:--with-http_geoip_module子產品
# tar xf GeoIP.tar.gz 
# cd GeoIP-1.4.8/
# ./configure 
# make && make install 
或:
# yum install geoip-devel -y
 2)錯誤提示:--with-google_perftools_module子產品
# tar xf libunwind-1.1.tar.gz
#  CFLAGS=-fPIC ./configure  
# make CFLAGS=-fPIC  
# make CFLAGS=-fPIC install 
# tar xf gperftools-2.1.tar.gz
#  cd gperftools-2.1
# ./configure 
#  make && make install  
# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
#  ldconfig
2、添加系統使用者
    # groupadd -r users
    # useradd -r -g users webuser
3、編譯配置
./configure \
--user=webuser \
--group=users \
--prefix=/opt/nginx \
--with-http_addition_module \
--with-google_perftools_module \
--with-http_flv_module \
--with-http_geoip_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-poll_module \
--http-client-body-temp-path=/opt/nginx/temp/client_body_temp \
--http-fastcgi-temp-path=/opt/nginx/temp/fastcgi_temp \
--http-proxy-temp-path=/opt/nginx/temp/proxy_temp \
--http-scgi-temp-path=/opt/nginx/temp/scgi_temp \
--http-uwsgi-temp-path=/opt/nginx/temp/uwsgi_temp | tee /home/nhl/tmp/nginx.out
make && make install && echo 888      
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /opt/nginx/conf/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/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
 
nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac