あーかいぶすハイディフィニション

ここはもう更新しとらんのじゃ

Nginx のソースからインストール

Nginx 1.0.0 が出てたので、Nginx 入門を読みながらインストールしてみた。

※ロケ地:Serversman@VPS

めんどくさい人向けにインストール時に利用したコマンド一覧
# yum install openssl* readline* zlib* gcc pcre* libxml* libxslt-devel
# useradd -s /bin/false nginx
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/subsys/nginx.lock --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module
# make
# make install
# chown -R nginx:nginx /var/run/nginx/
# vi /etc/init.d/nginx
# chmod a+x /etc/init.d/nginx
インスコ前のご注意

モジュールについては、http://wiki.nginx.org/ModulesJa 参照して何が標準で入るか確認すれ。一応書いておくと、

  • Nginxコア
    • 何もしなくてもモチロン入る、本体
  • 標準のHTTPモジュール
    • 「--without-なんとか」って書かない限り、ライブラリがあればインストールされる
  • オプションのHTTPモジュール
    • 「--with-なんとか」って書かないとインストールされない、もちろん対応ライブラリも必要
  • サードパーティのHTTPモジュール/サードパーティのNginxパッチ
    • 自分で用意して「--add-module+PATH」って書く必要がある

となるよ。SSL 通信用のモジュールが「オプションのHTTPモジュール」に分類されてるのが注意する点かなあ。EPELから入れると何が有効になってるのかは試してねーからわからん。時間があったら調べるよ!

configure
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/subsys/nginx.lock --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module

※「--user=nginx --group=nginx」を指定していますが、予めデフォルトシェルを /bin/false にして nginx ユーザを追加してあります。/bin/nologin を使ってもいいけど、ftp を利用する予定があるならやめたほうがいいかもねー。

上記の configure オプションを利用すると、ライブラリチェックされたあとに、以下のよーなメッセージが出力された。

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1 library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
make;make install

とくになし、configure が通ればライブラリは揃ってるので、心配することもないでしょう。

# /usr/local/sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
nginx: TLS SNI support disabled
nginx: configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/subsys/nginx.lock --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module
  • v は、一行目の「nginx: nginx version: nginx/1.0.0」のみを出力します。-V とすると、多少詳細な情報も出力してくれます。とにかくこれで、無事にインストールできましたね!
起動スクリプト

configureで色々細かく設定しててうざいと思ったかもしれませんが、オフィシャルの wiki に記述してある RHEL 向けの起動スクリプト使いたかっただけなんやな。とりあえず nginx バイナリへのパスが「/usr/local/sbin/nginx」なのと、pid ファイルへのパスが「/var/run/nginx/nginx.pid」になってる所、あとは nginx.lock になってる事を注意すれば、書き換えは大丈夫かな?とりあえず本家へのリンクと書き換え版の自家スクリプトをおいときますね。

http://wiki.nginx.org/RedHatNginxInitScript

#!/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:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx/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="/usr/local/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/etc/nginx/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