zoukankan      html  css  js  c++  java
  • 在 Ubuntu 9.10 Server 上安装 Nginx 0.8.34

    Nginx 在 3 月 3 日放出了 0.8.34 这个开发版。张宴也随即更新了《Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器》到第六版。不过,他写的记录是针对 CentOS、Redhat 等 rpm 包管理的服务器。由于习惯了 debian 系列的服务器,特别是用惯了 ubuntu 服务器,在这里特别做一下 Ubuntu 9.10 下的安装笔记。其他基于 deb 包管理的发行版也类似。

    首先,为了编译 Nginx,应在新装好的 Ubuntu server 环境下安装如下软件包:

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

    然后下载 0.8.34 版本的 Nginx:

    wget http://www.nginx.org/download/nginx-0.8.34.tar.gz

    解压:

    tar xvzf nginx-0.8.34.tar.gz

    下载 upstream fair 模块。upstream fair 是比内建的负载均衡更加智能的负载均衡模块。它采用的不是内建负载均衡使用的轮换的均衡算法,而是可以根据页面大小、加载时间长短智能的进行负载均衡。

    wget http://github.com/gnosek/nginx-upstream-fair/tarball/master

    解压:

    tar xvzf gnosek-nginx-upstream-fair-2131c73.tar.gz

    然后进入 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/mikespook/gnosek-nginx-upstream-fair-2131c73

    这个配置来自于 Jeff Waugh 的 PPA 中的 nginx 0.8.34 编译选项。配置、lock、pid 等文件的位置都是按照 ubuntu 系统惯例设置的。需要注意的是 –add-module 指向的是 upstream fair 的解压缩目录的绝对路径。这样就可以将 upstream fair 编译进 nginx。

    然后编译并安装:

    make && make install

    nginx 就安装成功了。目录 /var/lib/nginx 需要手工建立,否则启动 nginx 会报错:

    [emerg]: mkdir() "/var/lib/nginx/body" failed (2: No such file or directory)

    建立shell 脚本 /etc/init.d/nginx(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

    并执行命令:

    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

    控制 nginx 启动。
    其他配置不再累述,张宴的 blog 里写得非常清晰。只补充一下 upstream fair 的使用,只要在 nginx 配置文件的 upstream 段加入 fair 开关即可:

    upstream backend {
        server server1;
        server server2;
        fair;
    }

    当然,ubuntu 还可以用上面提到的 Jeff 的 ppa 源进行安装:

    echo "deb http://ppa.launchpad.net/jdub/devel/ubuntu hardy main" >> /etc/apt/sources.list
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E9EEF4A1
    apt-get update
    apt-get install nginx

    简单快捷。


    原文地址:http://www.mikespook.com/2010/03/%E5%9C%A8-ubuntu-9-10-server-%E4%B8%8A%E5%AE%89%E8%A3%85-nginx-0-8-34/


  • 相关阅读:
    【Jenkins】插件更改国内源
    【Jenkins】参数化引用
    【selenium】各种exception
    利用浏览器的console篡改cookie
    【python】django 分页器 Paginator 基础操作
    centos7 安装php7遇到的问题
    归并排序(自顶向下、原地归并)
    希尔排序
    插入排序
    选择排序
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218513.html
Copyright © 2011-2022 走看看