「apt-get install nginx で一発です」ではあまりにあまりなので、ソースを取得してビルドしてインストールしてみました。本当に静的ファイルを返すだけの目的だったので、ビルド オプションを付けてみたりとか。それでも至極簡単でビックリだったんですけどね。
インストールした環境は、Intel Pentium で動作する本当に最小構成の Debian GNU/Linux 6.0 (squeeze) で、まぁ、目新しい環境だとかそういう点は皆無です。中の人は、Apache は今までかなり弄ったものの、nginx を弄るのは全くの初めてという人。nginx は、一応、Debian のビルド パッケージとして提供されていますので、apt や aptitude で一発インストールできます。
# apt-cache show nginx Package: nginx Priority: optional Section: web Installed-Size: 608 Maintainer: Jose Parrella <bureado@debian.org> Architecture: amd64 Version: 0.6.32-3+lenny3 Provides: httpd Depends: libc6 (>= 2.7-1), libpcre3 (>= 7.4), libssl0.9.8 (>= 0.9.8f-5), zlib1g (>= 1:1.1.4) Filename: pool/main/n/nginx/nginx_0.6.32-3+lenny3_amd64.deb Size: 268654 MD5sum: 8ba00b9fa72c1b6d92ba1f4af5b95e2d SHA1: 24e1652ca0cb77532c25042c66909551aeeb4306 SHA256: 8fafcaf3ddcbed09c951c2c1a3fc1a8c25b90d96827bcb556976e1fcb82efddb ...
ただし、バージョンが 0.6.32 と古いこと*1と、ファイル サーバの共有ディレクトリに置かれた静的ファイルを、HTTP 経由で閲覧したいだけの目的で、CGI や PHP を動作させる必要やプロキシなどの機能は全く必要なかったため、勉強も兼ねてソースコードからビルドすることにしました。
$ # ソースコードを取得 $ cd ~/src $ wget http://nginx.org/download/nginx-1.0.11.tar.gz ... $ # アーカイブを展開 $ tar zxfv nginx-1.0.11.tar.gz ... $ # configure $ cd nginx-1.0.11 $ ./configure ... ./configure: error: C compiler gcc is not found
最小構成でインストールされた Debian で、ビルドに必要なコンパイラやライブラリが全く入っていなかったので怒られる(´・ω・`)
$ # ビルドに必要なツールのインストール $ apt-get install gcc make ... $ # 気を取り直して configure $ ./configure --user=www-data --group=www-data --without-pcre --without-http_gzip_module --without-http_ssi_module --without-http_userid_module --without-http_access_module --without-http_auth_basic_module --without-http_geo_module --without-http_map_module --without-http_split_clients_module --without-http_referer_module --without-http_rewrite_module --without-http_proxy_module --without-http_fastcgi_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module --without-http_limit_zone_module --without-http_limit_req_module --without-http_empty_gif_module --without-http_browser_module --without-http_upstream_ip_hash_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module ... Configuration summary + PCRE library is disabled + OpenSSL library is not used + using builtin md5 code + sha1 library is not used + zlib library is not used nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" ... $ # ビルド $ make ... $ # インストール $ make install ...
...と、ここまで驚くほどに超スムーズ。ファイル サーバとして共有しているディレクトリを、ルートからごっそり公開し、目的のファイルへのナビゲーションは autoindex に丸投げ。
$ # サーバ設定ファイルを編集 $ vi /usr/local/nginx/conf/nginx.conf ... charset utf-8; ... location / { alias /mnt/; autoindex on; autoindex_exact_size off; autoindex_localtime off; } ... $ # nginx を起動 $ /usr/local/nginx/sbin/nginx ...
...と、最後まで大きな問題もなく完了。ちょっとハマった点は以下。
ちゃんと動作確認できたので、起動スクリプトなどを用意する。
$ # 起動スクリプトを取得 $ wget -O /etc/init.d/nginx http://www.debianadmin.com/images/nginx ... $ # 起動スクリプトをセットアップ $ chmod 755 755 /etc/init.d/nginx $ update-rc.d -f nginx defaults