Ubuntu12.04でnginxをビルドする際のメモ、ミソはapt-getでインストールされる標準環境を踏襲できるあたり。
また今回はスピードの遅いファイルシステムに対するキャッシュ処理とキャッシュのパージ処理ができるモジュールを追加する。
- FRiCKLE Labs / nginx / ngx_slowfs_cache
http://labs.frickle.com/nginx_ngx_slowfs_cache/ - FRiCKLE Labs / nginx / ngx_cache_purge
http://labs.frickle.com/nginx_ngx_cache_purge/
▽ 下準備
ビルド用のライブラリ等のインストールを行う。
sudo apt-get install build-essential libpcre3-dev zlib1g-dev libssl-dev libgd2-xpm-dev libgeoip-dev
また、環境をうまく引き継ぐためにnginxも入れておく
sudo apt-get install nginx
なお、デフォルトでインストールされるnginxのビルドオプションを調べておくなら下記のコマンドを実行しておく
/usr/sbin/nginx -V
その後、設定ファイルのディレクトリに適当なファイルを作っておく
sudo touch /etc/nginx/dummy
さらにnginxを削除
sudo apt-get autoremove nginx
▽ 各種ソースコードのDL&展開
ビルドは~/srcで行う。
cd ~/src
wget http://nginx.org/download/nginx-1.2.0.tar.gz
wget http://labs.frickle.com/files/ngx_slowfs_cache-1.9.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-1.5.tar.gz
tar xf ./nginx-1.2.0.tar.gz ./ngx_slowfs_cache-1.9.tar.gz ./ngx_cache_purge-1.5.tar.gz
▽ ビルド&インストール
configure処理、必要のないオプションは適宜削除すれば良い
cd ~/src/nginx-1.2.0
./configure \
–prefix=/etc/nginx \
–sbin-path=/usr/sbin/nginx \
–conf-path=/etc/nginx/nginx.conf \
–error-log-path=/var/log/nginx/error.log \
–http-client-body-temp-path=/var/lib/nginx/body \
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
–http-log-path=/var/log/nginx/access.log \
–http-proxy-temp-path=/var/lib/nginx/proxy \
–http-scgi-temp-path=/var/lib/nginx/scgi \
–http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
–lock-path=/var/lock/nginx.lock \
–pid-path=/var/run/nginx.pid \
–with-http_addition_module \
–with-http_dav_module \
–with-http_geoip_module \
–with-http_gzip_static_module \
–with-http_image_filter_module \
–with-http_realip_module \
–with-http_stub_status_module \
–with-http_ssl_module \
–with-http_sub_module \
–with-ipv6 \
–with-sha1=/usr/include/openssl \
–with-md5=/usr/include/openssl \
–with-mail \
–with-mail_ssl_module \
–add-module=/home/ngidev/src/ngx_cache_purge-1.5 \
–add-module=/home/ngidev/src/ngx_slowfs_cache-1.9
あとはmake&install
make
sudo make install
起動や終了は標準スクリプトがそのまま利用できるので下記で可能となる。
sudo service nginx start | stop | restart