Ubuntu 10.04 TLS ã« nginx + passenger + sinatra ãå ¥ããã¡ã¢(2)
ååã®ç¶ããããã£ã¨ããã¾ã
mkdir tmp views public
ãã¦ãconfig.ru âä½æ
require 'application.rb' disable :run set :root, Pathname(__FILE__).dirname run Sinatra::Application
application.rbã®ä¸èº«ã¯ãããªãâ(ãã¤éå½¢)
# -*- coding: utf-8 -*- require 'rubygems' require 'sinatra' require 'haml' configure do set :views, "#{File.dirname(__FILE__)}/views" end error do e = request.env['sinatra.error'] Kernel.puts e.backtrace.join("\n") 'Application error' end helpers do # add your helpers here end not_found do 'not found' end get '/' do haml :index end
ã¨ãããã hello world ã¨ããã phpinfo() ç㪠views/index.haml â
!! XML !!! Strict %html %head %title sinatrainfo %meta{:"http-equiv"=>"Content-Type", :content=>"text/html", :charset=>"utf-8"} %link{:rel=>"stylesheet", :type=>"text/css", :href=>"style.css"} %body %p sinatrainfo table - @env.each do |k, v| %tr %td= k %td= v
views/style.css
body { font-size: 8pt; } table, tr, td, th { border: 1px solid black; border-collapse: collapse; } th, td { writing-mode: tb-rl; }
ã¡ãªã¿ã«ãsinatra ã£ã¦ã__END__ 以ä¸ã«ãã³ãã¬ã¼ãæ¸ããã¨ãåºæ¥ãã¤ã³ã©ã¤ã³ãã³ãã¬ã¼ãã£ã¦æ©è½ããã£ã¦è¶ ãæ°ã«å ¥ããªãã§ããâãããªã
require 'sinatra' get '/' do haml :index end __END__ @@ layout %html = yield @@ index %div.title Hello world!!!!!
ãªãã nginx + passenger ã®ç°å¢ã§ã¯ã¤ã³ã©ã¤ã³ãã³ãã¬ã¼ãã使ããªãã£ãããã¼ããªãã ãããªããããã»ã»ã»
ãã¾ã
CGIç°å¢ã§ sinatraåããå ´åãããªæã㧠dispatch.cgi ä½æ
#!/usr/bin/ruby load 'application.rb' set :run => false, :environment => :production Rack::Handler::CGI.run Sinatra::Application
.htaccess ã¯ãããªæãâã§
AddHandler cgi-script cgi DirectoryIndex dispatch.cgi <Files application.rb> deny from all </Files> RewriteEngine On RewriteBase /~hoge/helloworld/ # é©å½ã«ä¿®æ£ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) dispatch.cgi/$1 [L]