ubuntu下ngin(accesskey+session sticky+fair)编译安装笔记

ubuntu下nginx(含第三方模块:ngx_http_upstream_fair_module、HttpAccessKeyModule、nginx-upstream-jvm-route)的编译安装。


一、下载
nginx:                        http://nginx.org/en/download.html
ngx_http_upstream_fair_module:http://wiki.nginx.org/HttpUpstreamFairModule
HttpAccessKeyModule:          http://wiki.nginx.org/NginxHttpAccessKeyModule
nginx-upstream-jvm-route       http://code.google.com/p/nginx-upstream-jvm-route


二、编译安装环境准备


sudo apt-get install build-essential libpcre3-dev libssl-dev libxslt-dev libgd2-xpm-dev libgeoip-dev


三、安装
将nginx及第三方模块tar压缩包解压。


1、进入HttpAccessKeyModule的源码文件夹,修改config文件:
将 "$HTTP_ACCESSKEY_MODULE" 改为 "ngx_http_accesskey_module"


2、进入nginx源码目录,执行:
patch -p0 < /path/to/this/directory/jvm_route.patch
其中/path/to/this/directory/指的是nginx-upstream-jvm-route的源码文件夹绝对路径


3、进入nginx源码目录执行configure:
---------------------------------------------------------
./configure --conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--with-debug \
--with-http_stub_status_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-mail \
--with-mail_ssl_module \
--with-ipv6 \
--with-http_realip_module \
--with-http_geoip_module \
--with-http_xslt_module \
--with-http_image_filter_module \
--with-sha1=/usr/include/openssl \
--with-md5=/usr/include/openssl \
--add-module=/home/aiks/nginx-install/nginx-accesskey-2.0.3 \
--add-module=/home/aiks/nginx-install/gnosek-nginx-upstream-fair-2131c73 \
--add-module=/home/aiks/nginx-install/nginx_upstream_jvm_route

---------------------------------------------------------


注意--add-module后面的路径为模块源码目录所在位置。


4、编译:
sudo make


5、手工建立目录/var/lib/nginx


6、安装
sudo make install


四、配置
1、站点配置在/etc/nginx下(略)


2、建立shell 脚本 /etc/init.d/nginx
---------------------------------------------
#! /bin/sh


### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO




PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx


test -x $DAEMON || exit 0


# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi


set -e


case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
      echo -n "Reloading $DESC configuration: "
      start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
          --exec $DAEMON
      echo "$NAME."
      ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac


exit 0

---------------------------------------------


3、并执行命令:
sudo update-rc.d -f nginx defaults
更新 rc 后,即可使用:
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart 

你可能感兴趣的:(ubuntu下ngin(accesskey+session sticky+fair)编译安装笔记)