nginx 資料一覧
nginxインストール手順
2009/6/7更新
対応バージョン: 0.7.59
公式サイト
準備
導入OS
Ubuntu 9.04
管理用アカウント作成
% sudo groupadd -r www % sudo useradd -r -g www -s /bin/false -d /nonexistent www
インストール
配布ファイル展開
% tar zxvf nginx-0.7.59.tar.gz % cd nginx-0.7.59
make,インストール
% ./configure --user=www --group=www <オプション>
デフォルトで以下のモジュールが有効になる。
ngx_http_access_module
ngx_http_auth_basic_module
ngx_http_autoindex_module
ngx_http_browser_module
ngx_http_charset_module
ngx_http_empty_gif_module
ngx_http_fastcgi_module
ngx_http_geo_module
ngx_http_gzip_module
ngx_http_limit_req_module
ngx_http_limit_zone_module
ngx_http_map_module
ngx_http_memcached_module
ngx_http_proxy_module
ngx_http_referer_module
ngx_http_rewrite_module
ngx_http_ssi_module
ngx_http_upstream_ip_hash_module
ngx_http_userid_module
上記以外に必要なモジュールがあれば<オプション>で指定する。オプションでは以下のモジュールが使用できる。
ngx_http_addition_module
ngx_http_dav_module
ngx_http_flv_module
ngx_http_gzip_static_module
ngx_http_image_filter_module
ngx_http_random_index_module
ngx_http_realip_module
ngx_http_secure_link_module
ngx_http_ssl_module
ngx_http_stub_status_module
ngx_http_sub_module
ngx_http_xslt_module
ここでは以下のモジュールを有効にする。
WebDAVサポート
--with-http_dav_module
SSLサポート
--with-http_ssl_module
また、デフォルトで有効になるモジュールのうち必要ないものはあらかじめ無効にしておくことでパフォーマンスアップが図れる。
% make % sudo make install
インストール物 (man,infoは除く)
/usr/local/nginx/*/*
各種設定
/usr/local/nginx/conf/nginx.confにて基本的な設定を行う。
以下、主な設定項目について説明する。パスを設定するところで相対パスを指定した場合は/usr/local/nginxが起点となる。
サーバの待ち受けポート
http { : server { listen 80;
サーバルート
http { : server { : location / { root html;
インデックスファイル
リクエストが「/」で終わっている場合にインデックスファイルとして検索するファイルを指定する。
http { : server { : location / { : index index.html index.htm;
動作確認
デーモンを起動する。
% sudo /usr/local/nginx/sbin/nginx
待ち受けポートがLISTENになっているか確認する。
% netstat -nat|egrep '(Proto|:80)' Proto 受信-Q 送信-Q 内部アドレス 外部アドレス 状態 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
WebブラウザでlocalhostにアクセスできればOKである。
デーモンを終了する。
単にkillすればよい。
% sudo killall nginx
initスクリプト設置
Debパッケージで配布されているスクリプトをインストールする。
% sudo aptitude download nginx % sudo dpkg -i nginx_0.6.35-0ubuntu1_i386.deb ./etc/init.d/nginx
デーモンのパス変更(/usr/sbin -> /usr/local/nginx/sbin)、及びPIDファイルの指定を削除する。
% sudo sed -i 's_/usr/sbin/nginx_/usr/local/nginx/sbin/nginx_' /etc/init.d/nginx % sudo sed -i 's_--pidfile __' /etc/init.d/nginx % sudo sed -i 's_-p /var/run/$NAME.pid __' /etc/init.d/nginx % sudo sed -i 's_/var/run/$NAME.pid __' /etc/init.d/nginx