DebianサーバにRails環境を構築(2/3) 〜lighttpd/fastcgiのインストールと設定〜
このエントリーは「DebianサーバにRails環境を構築する(1/3) 〜ruby/rubygem/railsのインストール〜 | 京の路」の続きです。
前回のエントリーでruby/rubygems/railsのインストールは終了しました。
今回は、lighttpdとfastcgiのインストールおよび設定を行います。
Lighttpdのインストール
apt-cache searchでlighttpdが見つからなかったので、lighttpdの最新バージョンをソースからインストールします。
wget http://www.lighttpd.net/download/lighttpd-1.4.13.tar.gz tar -zxf lighttpd-1.4.13.tar.gz cd lighttpd-1.4.13/ ./configure --prefix=/usr/local/lighttpd make sudo make install
FastCGIのインストール
これはgemでらくちんに。
sudo gem install fcgi
Lighttpdの設定と起動
では次にLighttpdの設定ファイルを記述して、サーバを起動します。
まず/usr/local/lighttpd/conf以下にlighttpd.confを配置します。
cd /usr/local/lighttpd/ sudu mkdir conf cd conf vi lighttpd.conf
設定ファイルの内容は、できる限り単純にしました。
なお、サーバ上で動かすRaislアプリは/usr/local/lighttpd/RAISL_APPに配置するようにしています。
RAILS_APPは該当するアプリケーション名に変更してください。
server.port=3000 server.bind="localhost" server.pid-file="/var/run/lighttpd.pid"
server.modules=( "mod_setenv", "mod_rewrite", "mod_alias", "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog" ) server.document-root="/usr/local/lighttpd/RAILS_APP/public" server.indexfiles=( "index.html", "dispatch.fcgi" ) accesslog.filename="/usr/local/lighttpd/RAILS_APP/log/access.log" server.errorlog="/usr/local/lighttpd/RAILS_APP/log/error.log" server.error-handler-404="dispatch.fcgi" url.rewrite=( "^/$"=>"index.html", "^([^.]+)$"=>"$1.html" )
###fastcgimodule ##readfastcgi.txtformoreinfo fastcgi.server=( ".fcgi"=>( "localhost"=>( "socket"=>"/usr/local/lighttpd/RAILS_APP/tmp/sockets/RAILS_APP.fcgi.socket", "bin-path"=>"/usr/local/lighttpd/RAILS_APP/public/dispatch.fcgi", "bin-environment"=>("RAILS_ENV"=>"production"), "idol-timeout"=>10, "check-local"=>"disable", "min-procs"=>3, "max_procs"=>20 ) ) )
dir-listing.encoding="utf-8" dir-listing.activate="enable" dir-listing.hide-dotfiles="enable"
###accessmodule url.access-deny=("~","RCS","CVS",".svn",",v")
###mod_setenv $HTTP["url"]=~"^/rss"{ setenv.add-response-header=("Content-Type"=>"application/xml") }
mimetype.assign=( ".gif"=>"image/gif", ".jpg"=>"image/jpeg", ".jpeg"=>"image/jpeg", ".png"=>"image/png", ".css"=>"text/css", ".html"=>"text/html", ".htm"=>"text/html", ".js"=>"text/javascript;charset=utf-8", ".conf"=>"text/plain", ".text"=>"text/plain", ".txt"=>"text/plain", ".dtd"=>"text/xml", ".xml"=>"text/xml" )
Lighttpdの動作確認
では、lighttpdを起動してみましょう。
まずサーバに適当なRailsアプリを作成します。ここではアプリケーション名はtest_appにしておきます。
cd /usr/local/lighttpd sudo rails RAILS_APP
では先ほどのlighttpd.confのRAILSアプリをtest_appに書き換えてください。
そのあと、以下のコマンドでlighttpdを起動します。エラーがでなければ起動しているはずです。
/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/conf/lighttpd.conf
http://localhost:3000/にアクセスして、前回同様以下のような画面が表示されたらOKです。
さて、次はMySQLのインストールとLighttpdとApacheの連携です。
続きは以下のエントリーで。