Railsåå¼·ä¼@æ±äº¬ç¬¬23å ã«è¡ã£ã¦ããã2é±éé ãã ãã©ã¬ãã¼ãããã
åå¼·ä¼ã®å½¢å¼ã¯ ãã¤ãã®ãã¨ã ã
ãã ãä»åã¯è©¦é¨çã«ãæ¼é£æ親ä¼ããè¡ãªã£ãã
- ããã§è©±ãã¦ãããã¡ã«ãã¡è§£ãã¦ã»ãã·ã§ã³ãå¼¾ãã®ã§ã¯?
- ã»ãã·ã§ã³ã®æéãæ½°ãã¦é·ãèªå·±ç´¹ä»ãããªãã¦ããèªç¶ã«ç¸æãèªèã§ããã®ã§ã¯?
- ã»ãã·ã§ã³æ¡ãèªç¶ã«åºã¦ããã®ã§ã¯?
- å¤ã®ã飲ã¿ä¼æ親ä¼ããããå®ãæ¸ãã®ã§ã¯?
ã¨ãã趣æ¨ã ããããã好è©ã ã£ã模æ§ããã ãç§ã¯ã©ããå æ°ãåºãªãã¦é ãã¦ãã£ãã®ã§æ親ä¼ã¯æ®ã©åºã¦ãªãã
åå
ååã¯3ã¤ã®ã»ãã·ã§ã³ã«åãããã
- Rails 2.0ãèªãã
- åå¿è ã»ãã·ã§ã³ - Scaffoldã®åæ©å ã«
- ãã ãã åã
åå¿è ã»ãã·ã§ã³ã¯ååã¨åãå 容ã ããã ãScaffoldã¯è©¦ãã¦ã¿ãããã©ããã®å ã¸é²ããªãã¨ããRailsåå¿è ã®ããã«ãScaffoldã§çæãããã¢ãã«ãã³ã³ããã¼ã©ã¼ã解説ãã¦ãèªåã§ã³ã¼ããæ¸ãã¨ããã¾ã§æã£ã¦è¡ãã¨ãã趣æ¨ã ååã«å¼ãç¶ãã¦ãªã¼ãã¼ããã£ã¦ãã ãã£ã¦ãYuumi3ããã«ã¯ä¹! ã§ãä»åãScaffoldçµæã®è§£èª¬ã ãã§æéåãã¿ããããã®ããæ¹ã¯Railsã®åå¿è åã解説ã¨ãã¦ã¯çæ³çã ã¨æããã©ãæéã¯æå¤ã«æããã®ãã masuidriveãããè¨ã£ã¦ã ãã©ããèªåã§ããã ããªã5-10åã§çµãããã¨ããéçãªè¨³ãã
ä½ã£ãé¨å±ã«æºã¾ã£ã¦ãã ãã éè«ããã»ãã·ã§ã³ã¯ãªãã好ä¾ã«ãªã£ã¦ãããã©ããã®ä¼ç»ã¯ã¨ã¦ãè¯ãããã ãã åã£ã¦ãããã¡ã«è²ã ã¨ã¢ã¤ãã£ã¢ã湧ãã¦ãã¦ããã®å ´ã«éã¾ã£ã¦ã人ã®ç¥æµãçµéãã¦ãã®åãå¢ãã§è§£æãé²ãã ãããããã¯ããã§ãããã£ããããã
ä»åã¯æ¼é£æ親ä¼ããã£ãé¢ä¿ä¸ãæ親ä¼ã¨ãã ãã ã»ãã·ã§ã³ã¯å°ç¶ãã ã£ããããããã®æ§å㯠shachiãããã¬ãã¼ããã¦ã ã ãã®æã®ã¤ãã³ãã¯çµå±ãæ親ä¼ã¨ãã§ããéè«ãä¸çªå¤§åã ã£ããããããã ããããã ãã ã»ãã·ã§ã³ã¯ãã®ã¡ãªãããåå¼·ä¼æéå ã«åãå ¥ãã試ã¿ãã¨ãè¨ããã
Rails 2.0
ãã¦ãéè«ã»ãã·ã§ã³ãè¤ãã¦ããã¦ä½ã ãã©ãç§ã¯Rails 2.0ã»ãã·ã§ã³ã®ãªã¼ãã¼ããã£ãã ç¾å¨Rails 2.0ã®Preview Releaseãåºã¦ããã®ã§ãããçºãã¦ã¿ããã¨ããã»ãã·ã§ã³ã
ç§ã¯2.0å¤æ´ç¹ãå ¨ç¶ææ¡ãã¦ãªãã®ã§ã詳ãããã¨ã¯ 諸æ©ãã ãã¡ã«æãã¦è²°ããªããã»ãã·ã§ã³ãé²ãããåã«ãæ¸ãããã©ãRailsåå¼·ä¼@æ±äº¬ã§ã¯ããããã¿ã¤ãã®ã»ãã·ã§ã³ãªã¼ãã¼ã¯å¤§æè¿ãªã®ã ãã¤ã¾ããããããç¥ããããã誰ãæãã¦ãã ãããã¨è¨ã£ã¦ã»ãã·ã§ã³ãéãã¦ãããã§è²ã 質åãããããããããã¿ããªæããã«ã©ãã©ãã»ãã·ã§ã³ã主å¬ãã¦æ¬²ããã
ã§ãçµè«ã¨ãã¦ã¯ãRails 2.0ã¯ããã»ã©é©ãã¯ãªãã
- ActiveResourceãå ¥ã£ã
- ãããã©ã¤ã¨ã¿ãªãªDBMSã¸ã®ãã©ã¤ãã¯ãã©ã°ã¤ã³ã«è¿½ãåºãã
- acts_asç³»ã¯ãã©ã°ã¤ã³ã«è¿½ãåºãã
ãã³ãã¬ã¼ãã®ãã¡ã¤ã«åè¦ç´ãå¤ãã£ãã(å¤ãè¦ç´ãèªèããã¿ãã)
- ããã³ãã¬ã¼ãåã.ãåºåãã©ã¼ãããæ¡å¼µåã.ããã³ãã¬ã¼ãã¨ã³ã¸ã³æ¡å¼µåã
- ä¾ãã°ãä»ã¾ã§ã®"list.rhtml"ã¯"list.html.erb"ã«ãªãã
Migrationãæ ¼å¥½è¯ããªã£ãã
ããã¤ãã®å¤æ´ç¹ã«ã¤ãã¦è©²å½é¨åã®ã½ã¼ã¹ã³ã¼ããå¼ãã§ã¿ããã©ãæ®éããªãã¨ããããé©ãããªããã¾ãé å½ã«é²åããã¨ãããã¨ãªãã ãããã
xibbarããã®ã¹ã©ã¤ã ãé常ã«è©³ç´°ãªã®ã§ããã¡ããåç §ãã»ãã·ã§ã³ã§ããã®ã¹ã©ã¤ããã¿ããªã§è¦ãªããé²ãããã¦ããã£ãã ãã¨ã¯ id:faultierããã®ã¬ãã¼ã ã詳ããã
詳細ãªè³æãããã®ã§ç§ã¯ãã以ä¸ã¯æ¸ããªãã
å¾å
å¾åã¯4ã¤ã®ã»ãã·ã§ã³ã«åãããã
- åå¿è ã»ãã·ã§ã³ - ãããã¯ã·ã§ã³ç°å¢ã®æ§ç¯
- engineããgeneratorã¸ã®ç§»è¡
- ãããã¡ã¤ã«ã®è©±
- éçºç°å¢ã®è©±
ç§ã¯ãããããã¯ã·ã§ã³ç°å¢ãã®ãªã¼ãã¼ã«ãªã£ããRailsã¢ããªã±ã¼ã·ã§ã³ã®éçºã®ä»æ¹ã¯ã¹ã¯ãªã¼ã³ãã£ã¹ãããªããã§è²ã ã¨åºåã£ã¦ãã®ã«å¯¾ãã¦ãå®éã«ã¢ããªã±ã¼ã·ã§ã³ãéç¨ããæ¹æ³ã¯ããã¾ã§ã¯åºåã£ã¦ãªã(ãããæ¢ãã°ãããªãã«ãããã©)ãããã1ã¤èª¬æãã¾ããããã¨ããã»ãã·ã§ã³ã
äºãèªãµã¼ãã¼ã«ä»è¾¼ãã§ããã¦ãå®éã«ãµã¼ãã¼ã®è¨å®ããããã£ã¦è¦ããªãã解説ããã
以ä¸ã«ãããä»®å®
- ç°å¢ã¯Debian etchã
- ãµã¼ãã¼ã¯rails-tokyo-23.yugui.jpã¨ãããµã¼ãã¼ã
- Railsã®ãããã¤å 㯠/var/rails-toky-23/current/ ã¨ãããã£ã¬ã¯ããª
ã¾ãã次ã®ç¥èãåæã¨ãã
- Railsã§scaffoldãã¦ä¸èº«ãçºãããããã¯ãã£ããã¨ããããã¨ã
- Apacheã®è¨å®ããªãã¨ãªãã¯å¼ã£ããã¨ããããã¨
ã¡ãªã¿ã«ãä¸éã§ã¯ãã®æã®ãæ軽ãµã¼ãã¼ã«ã¯CentOSã人æ°ã ãã©ãåè¦ãæ¿ç¥ã§è¨ããªãæç¶debianã ãç§ã«ã¯ãµã¼ãã¼ã«CentOSã¨ãã¾ãã¦Fedoraã使ãæå³ãåãããªããyumã£ã¦éããæ©è½ãapt-getç¸å½ã§ãã? Debianç³»ãªãæ´ã«æ¥½ãªaptitudeããããã!! ãæ¯ãã¦ã+ãµãã¼ããã§Redhatãåããªãåãããã©ãã§ããå ¸åçãªæ§æãä½ã£ã¦ãã®ã¾ã¾ä½¿ããªãã¨ããããããããã¨è©¦ãããã®ãµã¼ãã¼ã«ã¯Debianç³»ããããDebianãUbuntuã ã
éç¨ç°å¢ã®é¸æè¢
éç¨ç°å¢é¸æè¢ã¨ãã¦ä»åã¯æ¬¡ãç´¹ä»ããã
以ä¸ã§ã¯ãããã®é¸æè¢ãé çªã«è§¦ãã¦ããã
WEBrick, Mongrel
Railsã®éçºç¨ãµã¼ãã¼ã¨ãã¦ã¯WEBrickã¨Mongrelã主æµã§ãããå人ã®ã¡ãã£ã¨ãããµã¼ãã¹ãªããã®éçºç¨ãµã¼ãã¼ããã®ã¾ã¾daemonåãã¦ãååã§ããã ã»ãã·ã§ã³ã§èãã¦ã¿ãããéçºã«ã¯WEBrickã使ã£ã¦ãã人ãå¤ãã£ããWEBrickã¯Ruby 1.8æ¨æºæ·»ä»ãªã®ã§ã©ãã§ãåããã便å©ã ãã
ã§ããã©ãããªãMongrelã使ã£ãã»ããèµ·åãéãã¦ãããMongrelã¯ä¸»ã«Railsã®ããã«ä½ãããç°¡æHTTPãµã¼ãã¼ã ãä¸é¨ã®ã³ã¼ããCæ¡å¼µã©ã¤ãã©ãªã¨ãã¦æ¸ãã¦ãã®ã¨ãæ©è½ãçµãè¾¼ãã§ããåã ãWEBrickããéãã
Mongrelã®ã¤ã³ã¹ãã¼ã«ã¯
# gem install --include-dependencies mongrel
ããã ããMongrelãã¤ã³ã¹ãã¼ã«ãã㨠script/server ã¯ããã©ã«ãã§WEBrickã®ä»£ããã«Mongrelã使ãããã«ãªããMongrelã¤ã³ã¹ãã¼ã«å¾ã«æ¢ãã¦WEBrickã使ãããå ´åã¯
$ ruby script/server webrick
ã¨ããã
ã¾ããã®è¾ºã¯å¥½ã¿ã§ã -d ãªãã·ã§ã³ã渡ãã° script/server ã¯daemonã«ãªãã®ã§
# ruby script/server -p 80 -e production -d
ã¨ãããã°ããã ãã§éç¨ç°å¢ã«ãªããWEBrickãMongrelã¯ãRailså¼ã³åºãé¨åã¯ã·ã³ã°ã«ã¹ã¬ããã§å¦çããã®ã§éçã¯ããããã©ãç§ãããã®ãã¼ã¸ãã¥ã¼ã1æ¡ãªãã¾ãã使ããã
詳ãã㯠ruby script/server --help åç §ã
mod_proxy_balancer + Mongrel
ãã¦ãApacheã®ãã¼ã¸ã§ã³ã2.2ã«ä¸ãããããªã mod_proxy_balancer ã¯è¯ãé¸æã ã2.2ã§å°å ¥ãããApacheæ¨æºã®ã¢ã¸ã¥ã¼ã«ã§ãApacheã®Proxyæ©æ§ã«ç°¡æãã¼ããã©ã³ãµã¼æ©è½ãçµã¿è¾¼ãã§ãããã
apache ââââââ(HTTP)ââââ¬â mongrel (proxy_balancer) ââ mongrel ââ mongrel ââ ...
ãã®æ§æã¯
Apacheãããã³ãã«ç«ã¦ã
- Apacheã¯ç»åãã¹ã¿ã¤ã«ã·ã¼ããªã©ã®éçã³ã³ãã³ãã¸ã®ãªã¯ã¨ã¹ããæãã
- æ®ãã®åçã³ã³ãã³ãã¸ã®ãªã¯ã¨ã¹ããMongrelã«å§è²ããã
Mongrelã¯è¤æ°ç«ã¡ä¸ãã¦ãã
è¨å®ä¾:
<Proxy balancer://mongrel_cluster> BalancerMember http://127.0.0.1:8000 BalancerMember http://127.0.0.1:8001 BalancerMember http://127.0.0.1:8002 Order allow,deny Allow from all </Proxy> <VirtualHost *> ServerAdmin [email protected] ServerName rails-tokyo-23.yugui.jp ServerSignature On DocumentRoot /var/rails-tokyo-23/current/public <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/rails-tokyo-23/current/public/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/rails-tokyo-23.access.log combined ErrorLog /var/log/apache2/rails-tokyo-23.error.log RewriteEngine on RewriteLog /var/log/apache2/rails-tokyo-23.rewrite.log RewriteLogLevel 1 # on web_disable'd RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [L] # static index page RewriteCond %{DOCUMENT_ROOT}/index.html -f RewriteRule ^/$ /index.html [QSA] # Rails cached pages RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" </VirtualHost>
ã¾ãVirtualHostã®ä¸è¬çãªè¨å®é¨åã¯ããã¨ãã¦ã
DocumentRoot /var/rails-tokyo-23/current/public
DocumentRootã«ã¯Railsã® public ãã£ã¬ã¯ããªãæå®ãããéçãã¡ã¤ã«ã¯Apacheãåãæ±ãããã ã
åé ã®
mod_rewriteã¯ãApacheå é¨ã§ãªã¯ã¨ã¹ãURIãæ¸ãæãã¦æè»ã«ãªã¯ã¨ã¹ããå¦çããããã®æ¨æºã¢ã¸ã¥ã¼ã«ã ãã¾ããã®ã»ãã·ã§ã³ã«æ¥ã¦ãã人ã¯ã¿ããªç¥ã£ã¦ããã¿ããã ãã© ããããã®mod_rewriteé¨åãè¦ã¦ãããã
# on web_disable'd RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [L]
ããã¯ãpublic/system/maintenance.htmlã¨ãããã¡ã¤ã«ãåå¨ãããä»ãµã¤ãã¯ã¡ã³ããã³ã¹ä¸ã¨ãããã¨ãªã®ã§maintenance.htmlã®å 容ãåºåãã¦çµãããã¨ãã話ã
# static index page RewriteCond %{DOCUMENT_ROOT}/index.html -f RewriteRule ^/$ /index.html [QSA]
ãããããindexãã¼ã¸ã®ãã£ãã·ã¥ãåå¨ãããããã使ãã¨ãã
# Rails cached pages RewriteRule ^([^.]+)$ $1.html [QSA]
ãªã¯ã¨ã¹ãã«æ¡å¼µåãä»ãã¦ãªãã£ããHTMLæ±ãããã¨ãã
ãã®è¾ºã¯Railsæ¨æºã® public/.htaccess ããã³ãã¼ãã¦ãã¦ã¡ãã£ã¨æãå ããã ãã rails ã³ãã³ãã§ã¢ããªã±ã¼ã·ã§ã³ã®éå½¢ãä½ã£ãæç¹ã§ public/.htaccess ã£ã¡ã ãã®ãä½ããã¦ããã ãã©ãä½ã«ãã¦ãRailsã®é åè¨å®ã¯ãã® public/.htaccess ãã¨ã¦ãåèã«ãªãã
ãã¦ãããã§æå¾ã®ã¨ãããã
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
ãªã¯ã¨ã¹ãã«ããããããã¡ã¤ã«ãåå¨ããããRailsããã£ãã·ã¥ãä½ã£ã¦ããã¨å¤æãã¦ãã®ãã¡ã¤ã«ããã®ã¾ã¾è¿ãã
ãã®æç¹ã§ãå ã®æ¸ãæãã«ãã£ã¦ç¢ºå®ã«æ¡å¼µåãä»ãã¦ããã®ã§ãRailsããã¼ã¸ãã£ãã·ã¥ãä½ã£ã¦ããã° public/controller_name/action_name.html ã¨ãããååã§åå¨ããã¯ãã§ã %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f ã«ãã£ã¦ãã£ãã·ã¥ã®æç¡ãå¤å¥ã§ããã®ã ã
ãã¡ã¤ã«ãåå¨ããªãã£ããããã¯åçãã¼ã¸ã¸ã®ãªã¯ã¨ã¹ãã§ããå¯è½æ§ãããã¨å¤æãã¦mongrelã«è»¢éãããçµããã
ããã¯ã°ã©ã¦ã³ãMongrel
ããããããã¯ã°ã©ã¦ã³ãã®Mongrelããã»ã¹ã¯ã©ããã£ã¦ç«ã¡ä¸ããã®ããç§ã¯ã»ãã·ã§ã³ã§ã¯capistranoã§ç«ã¡ä¸ãã¦ãã¾ã£ãã
capistranoã使ããªããªããããã¯ã°ã©ã¦ã³ãã®mongrelã®ç«ã¡ä¸ãã«ã¯mongrel_clusterãããã ããããããgemã§å ¥ããããã
# gem install --include-dependencies mongrel_cluster
è¨å®ã¨ã詳ãããã¨ã¯ ããªã±ã³ããã¨ãåç § !
capistrano
ã»ãã·ã§ã³ã§ä½¿ã£ãcapistranoã®è¨å®ã¯ å ¬å¼ãµã¤ãã®è¨è¿° ãåèã«ããã
ãããªæãã® script/spin ãä½ã£ã¦ã
#!/bin/sh `dirname $0`/process/spawner -a 127.0.0.1 -p 8000 -i 3
config/deploy.rb ããããªæãã«ç·¨éãã¦
set :application, "example" set :repository, "http://svn.yugui.jp/misc/trunk/example-app" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: set :deploy_to, "/var/rails-tokyo-23" # If you aren't using Subversion to manage your source code, specify # your SCM below: # set :scm, :subversion role :app, "rails-tokyo-23.yugui.jp" role :web, "rails-tokyo-23.yugui.jp" role :db, "rails-tokyo-23.yugui.jp", :primary => true set :ssh_options, :port => 422 set :use_sudo, false namespace :deploy do task :restart, :roles => :app do stop start end end
capistranoã«ã¤ãã¦ã¯ä»åã¯æ·±ãã¯è§¦ããªããå¸æè ãããã次åã®åå¼·ä¼ã§ã»ãã·ã§ã³ãããããªã 以åã®Railsåå¼·ä¼ã§ãã£ãã»ãã·ã§ã³ã®è¨é² ãããã®ã§åç §ã
ã Railsã«ããã¢ã¸ã£ã¤ã«Webã¢ããªã±ã¼ã·ã§ã³éçº ç¬¬2ç ãã«ãè¼ã£ã¦ããã©ãææ°çã®capistrano 2.0ã«ã¯å¯¾å¿ãã¦ããªãã®ã§æ³¨æãã¾ãã1.1ã®è¨å®ã§ãåºæ¬çã«ã¯åããããããã ãã©ã
ä¸åº¦æ £ãã¦ãã¾ãã¨æã§ã¡ã¾ã¡ã¾ãµã¼ãã¼èµ·ããããæ¢ãããã¡ã³ããã³ã¹ç»é¢åºããããã£ã¦ãããªãã®ã§ç§ã¯ä»åãcapistrano使ãã¾ãããã¨ããã ããRailsã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤èªä½ã¯åã«ã½ã¼ã¹ããªã¼ããµã¼ãã¼ã«ã³ãã¼ããã°ããã®ã§capistranoã使ããªãã¦ãscpã§ãæ¸ãã
Apache + FastCGI
Mongrel以åã«ä¸»æµã ã£ãææ³ã ãä»ãæç¨ãã¦ãã人ã¯ããã
æ§æã¯ãããªæããapacheã¨ãããã¯ã°ã©ã¦ã³ãã®ã¯ã¼ã«ã¼ããã»ã¹ãFastCGIãããã³ã«ã§ç¹ãã
apache ââ(Fast CGI)ââ¬â worker ââ worker ââ worker ââ ...
FastCGIã使ãã«ã¯ã¾ããApacheã®FastCGIç¨ã®ã¢ã¸ã¥ã¼ã«ãç¨æããå¿ è¦ããããApacheç¨ã®FastCGIã¢ã¸ã¥ã¼ã«ã«ã¯mod_fastcgiã¨mod_fcgidãããããããã§ã¯ mod_fcgid ã使ç¨ãããmod_fastcgiã¯ãªããéçºæ¢ã¾ã£ã¦ãããã?
ã¯ã¼ã«ã¼ããã»ã¹ã¯äºãç«ã¡ä¸ãã¦ãããã¿ã¼ã³ã¨ãapacheã«ç®¡çããããã¿ã¼ã³ããããç§ã¯apacheã«ä»»ããã®ã楽ã§å¥½ããã¯ã¼ã«ã¼ãæ»ã¬ã¨é©å½ã«ç«ã¡ä¸ãã¦ããããããããããã¾ããã®ã¸ãã¯æ¬æ¥ã¯ daemontools ãæ¬å¼ãªæ»æ´»ç£è¦ã·ã¹ãã 使ãã¨ãã話ããç¥ããªããã©ã
Debianãªãã¤ã³ã¹ãã¼ã«ã¯apt-getããã ãã
# apt-get install libapache2-mod-fcgid
è¨å®ä¾
<VirtualHost *> ServerAdmin [email protected] ServerName rails-tokyo-23.yugui.jp ServerSignature On DocumentRoot /var/rails-tokyo-23/current/public <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/rails-tokyo-23/current/public/> Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride None Order allow,deny allow from all FCGIWrapper "/var/rails-tokyo-23/current/public/dispatch.fcgi" .fcgi RewriteEngine On RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] </Directory> Addhandler fcgid-script .fcgi DefaultInitEnv RAILS_ENV production # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/rails-tokyo-23.access.log combined ErrorLog /var/log/apache2/rails-tokyo-23.error.log RewriteEngine on RewriteLog /var/log/apache2/rails-tokyo-23.rewrite.log RewriteLogLevel 9 # on web_disable'd RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [L] # static index page RewriteCond %{DOCUMENT_ROOT}/index.html -f RewriteRule ^/$ /index.html [QSA,L] ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" </VirtualHost>
å¤ãã£ãã®ã¯
FCGIWrapper "/var/rails-tokyo-23/current/public/dispatch.fcgi" .fcgi RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
mongrelã¸ã®ãããã·ã®ä»£ããã«ã¯ã¼ã«ã¼ããã»ã¹ã«ãªã¯ã¨ã¹ããåãããã«ãããã ãªãã¯ã¼ã«ã¼ããã»ã¹ã®å®ä½ã§ãã dispatch.fcgi ã¯railsã³ãã³ããæåã« public/ å ã«çæãã¦ããã¦ãçã
Lighttpd + FastCGI
ãã1ã¤äººæ°ã®ããæ§æä¾ã¨ãã¦ã¯ Lighttpd ã使ããã®ãããã
Lighttpdã¨ããã®ã¯Apacheããã軽éãªwebãµã¼ãã¼å®è£ ã§ãLLãªwebã¢ããªã±ã¼ã·ã§ã³ã®é åç°å¢ã¨ãã¦ã¯çµæ§æåã ã"Lighttpd"(ããã¨ããã¡ã¦ãã¼ã¦ãã¼ã´ã¼ã§ãã¼)ã¯çºé³ãã¥ããã®ã§ã¿ããªLighty(ããã¦ãã¼)ã¨å¼ã¶ã
Lighttpdã¯Apacheããã¯æ©è½ãå°ãªããããã®åã ã軽éã§é ä¿¡ãéããmongrelããã¡ãã¡å®è£ ããã¼ã£ã¦ããã®ã¨ã¯éã£ã¦æ¬å¼ã®webãµã¼ãã¼ã ãé«è² è·æã®å®å®æ§ã§ã¯Apacheã«å£ãã¨ããæè¦ãããããã¾ããé常ã¯å¤§ä¸å¤«ã ã
Lighttpdã¯FastCGIã¢ã¸ã¥ã¼ã«ãæ¨æºã§ä»ãã¦ããä¸ã«ãæ´»çºã«ã¡ã³ããã³ã¹ããã¦ããããããRailsããªããã®ãããã¤ç°å¢ã¨ãã¦äººæ°ãéããçç±ã ããã
å¤ãã®Linuxãã£ã¹ããªãã¥ã¼ã·ã§ã³ã§ã¯ããã±ã¼ã¸åããã¦ãã¦ãDebianã§ã
# apt-get install lighttpd
ã ãã§å ¥ãã
è¨å®ä¾
è¨å®ã¨ããããLighty + FastCGI ãèµ°ãããä¸çªç°¡åãªæ¹æ³ã¯Railsã¢ããªã±ã¼ã·ã§ã³ã®ãã£ã¬ã¯ããªã§
# ruby script/server lighttpd -p 80 -e prouction -d
ã¨ããããã¨ã ãèªåçã« config/lighttpd.conf ãçæããã¦ããããèªã¿è¾¼ãã§Lighttpdãç«ã¡ä¸ãããFastCGIã®ã¯ã¼ã«ã¼ããã»ã¹ã¯Lighttpdã管çãã¦ãããã
ãã®è¦é ã§éçºç¨ãµã¼ãã¼ã«ãLighttpdã使ã£ã¦ãã人ããããä½ãããRailsã®å ´åã¯developmentç°å¢ã§ã¯ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¼ã®åèµ·åãå¿ è¦ã«ãªããã¨ã¯å¸ã ããå°ããªããã ãªãããåèµ·åãå¿ è¦ã«ãªã£ã¦ãLighttpdã¯èµ·åãApacheããéããã
ããã§ãã¾ããèªåçæãããã®ã¨åæ§ã®è¨å®ã/etc/lighttpd.confã«ãã¦ãã£ã¦ãè¯ãã Apacheã®è¨å®ã¨ã¯ææ³ãããªãç°è³ªã ãã©ãæ¡ä»¶ç¯ãæ¸ããããã¦ããã°ã©ã çã§ã¡ãã£ã¨é¢ç½ãã
$HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" { server.max-keep-alive-requests = 0 } $HTTP["url"] =~ "^/doc/|^/images/" { dir-listing.activate = "enable" }
åæç¶æ ã®è¨å®ãã¡ã¤ã«ããrailsã¢ããªã±ã¼ã·ã§ã³ã«å¯¾å¿ãã¦ãããªãã以ä¸ã®ãããªæãã
server.modulesã®èªã¿è¾¼ã¿ãªã¹ãã«mod_fastcgiã足ãã
FastCGIã®è¨å®ã¨ãã¦æ¬¡ã追è¨ã
server.error-handler-404 = "dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( ( "min-procs" => 1, "max-procs" => 3, "socket" => "/var/run/lighttpd/rails.sock", "bin-path" => "/var/rails-tokyo-23/current/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "production" ) ) ) )
ãã¤ã³ãã¯"404 Not Found"ã®ãã³ãã©ã¨ãã¦FastCGIãè¨å®ãã¦ãããã¨ã ãªãããã¯Apacheã®ã¨ãã«ããã£ãã·ã¥ãã¡ã¤ã«ããªãã£ããmongrelã«è»¢éãã¨ãæ¸ããã®ã¨åããã¨ã
ä»ã®é¸æè¢
Pound
Pound + Apache + Mongrelã¨ããã®ãããããã©ããå¾®å¦ã ã¨æãã®ã§æéã®é½åããã£ã¦ç´¹ä»ããªãã£ããPoundã£ã¦ããã®ã¯è»½éã®ãã¼ããã©ã³ã¹ã»ã½ããã¦ã§ã¢å®è£ ããã®å ´åã¯æ§æã¯æ¬¡ã®ããã«ãªãã
Pound ââ¬â Apache â mongrel â mongrel â mongrel â ...
Poundã使ããã¿ã¼ã³ã¯ã Railsã«ããã¢ã¸ã£ã¤ã«Webã¢ããªã±ã¼ã·ã§ã³éçº ç¬¬2ç ãã«è¼ã£ã¦ãã®ã§å¿ è¦ãªããã£ã¡ãåç §ã
å¾®å¦ã¨ããã®ã¯ãã¤ã¾ããã¼ããã©ã³ã¹ãPoundã«è¿½ãåºãã»ã©ã®è² è·ãApacheã«æãããã¨ã¯ããã®ããªãã¨ãããã¨ãRailsã¢ããªã±ã¼ã·ã§ã³ã§Apacheãããã«ããã¯ã«ãªããã¨ã¯å°ãªãããããªãããããã ã¨ããã¨ããã¼ããã©ã³ãµã¯mod_proxy_balancerã§ãããããªããã¨æãã
ã¾ããApachetã2.1ã ã£ãã1.x系統ã ã£ãããã¦ã使ããã¨ããå©ç¹ã¯ããããç¥ããªããã§ãã2.1ãªãããæ½ã2.2ã«ä¸ãã¡ãããªYO!
SCGI
SCGIã¨ããWebãµã¼ãã¼ - ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¼ééä¿¡ã®ããã®ãããã³ã«ããããFastCGIãmod_jkã¨ä½ç½®ã¥ãã¨ãã¦ã¯åãã ãããã®rubyçãµã¼ãã¼ã©ã¤ãã©ãªã¨ãrails対å¿ã¨ããã®ãããã
ããã©ããããã®ä½è ã®Zed Shawãçµå±ãmongrelãä½ã£ã¦ãã£ã¡ã«ç§»è¡ãã¦ãã¾ã£ãã ä½è ã¨ãã¦mongrelã®ã»ããããã¨ããå¤æã§ãã£ã¡ãã¡ã¤ã³ã«ããã®ã§ãããªããä»å¾ã®ã¡ã³ããã³ã¹ãä¸å®ã ãããããããªãã
AJP
AJPã¨ãããããã³ã«ããããApacheã¢ã¸ã¥ã¼ã«ã®å®è£ ã§ããmod_jkã®ååã§ãç¥ããã¦ãããFastCGIãSCGIã¨åãä½ç½®ã¥ãã ãApacheã¨Java Servletã³ã³ãããç¹ãã®ã«ãã使ããã¦ãããããã®rubyçãµã¼ãã¼ã©ã¤ãã©ãªã¨rails対å¿ã¯ç§ãæ¸ããã
ã§ããã¾ã ä¸å®å®ã ããé度ãåºãªããããããªç¶æ ã§æ¾ç½®ãã¦ããã®ã§ããããããªããã§ãApacheãµã¤ãã§Javaã®ç¥è¦ãæ´»ãããæè¡ã§ããããã ããç§ã¨ãã¦ã¯AJPã®é襲ãããã¤ããã¯ããããã®ãã¡ããããã§ããããã«ãªã£ããã¾ãè¨äºãæ¸ãã
飲ã¿ä¼
ä»åã¯æ親ä¼ãæ¼ã«ãã£ãã®ã§ã飲ã¿ä¼ã¯ã¨ãã«å¼ã³ãããªãã£ã模æ§ãããã§ãè¡ããã人ã¯ãããã飲ã¿ã«è¡ã£ãã¿ããã ãã©ã
ç§ã¯ããªããä¸å®çç¶ã¨ãç²å´æãã²ã©ãã£ãã®ã§æ©ã ã«å¸°ã£ã¦ãã¾ã£ããã¨ããããã§é£²ã¿ä¼ã§ã®éè«&ä¸å¤ªè©±ã¯ç¡ãã
ãªãããåå¼·ä¼ã®éä¸ããã©ããããããªãç²ããæãã¦ããã¤ã«ãã¾ãã¦ãã½ãã½ã¨åã£ã¦ãã¨æããèãã¥ããã¦ããã¾ããã
åèè³æ
Official Documents:
-
Apacheè¨å®ã®è³æã¨ãã¦ã¯ä½ãç½®ãã¦ãã¾ãå ¬å¼ã®ããã¥ã¡ã³ãã ãä¸å¯§ã ãã主ãªã¨ããã¯æ¥æ¬èªçããããã
-
ãã¡ããè¨å®ã«å¿ è¦ãªä¸éãã®ãã¨ã¯å ¬å¼ããã¥ã¡ã³ãã§ååã(è±èª)
-
Capistranoã¯æ¬è¨äºå·çæç¹ã§ã¯å ¬å¼ãµã¤ãã®ããã¥ã¡ã³ãã¯ããã¾ãå å®ãã¦ãªãã(è±èª)
Books:
Agile Web Development with Rails, 2nd Ed. ( Railsã«ããã¢ã¸ã£ã¤ã«Webã¢ããªã±ã¼ã·ã§ã³éçº ç¬¬2ç )
第2çã§ã¯ãããã¤ã«é¢ããè¨è¿°ãå å®ãããPoundã使ã£ããã¿ã¼ã³ãããã³Capistranoã«ã¤ãã¦è§£èª¬ãã¦ããã
-
ãªã©ã¤ãªã¼ã®PDFæ¸ç±ã(è±èª)
Capistrano and the Rails Application Lifecycle
ãªã©ã¤ãªã¼ã®PDFæ¸ç±ãæãRailsã®ãªã³ã©ã¤ã³ããã¥ã¢ã«ãµã¤ãã«ç½®ãã¦ãã£ãcapistrano解説ãã¾ã¨ããã£ã½ããCapistrano 1.2対å¿ã2.0ã¯å¯¾å¿ãã¦ããªã模æ§ã
Reports: