[心得] Lighttpd 跑 Rails and PHP 設定

看板Ruby作者 (lala)時間18年前 (2006/09/14 08:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
這個網頁是 lighttpd 單獨跑 Rails 設定 http://lightyror.blogspot.com/2006/09/lighttpd-rails.html 這個網頁是 Multi Domain 來跑 Rails and PHP 設定 http://lightyror.blogspot.com/2006/09/lighttpd-rails-domain.html 這個網頁是 Single Domain 跑 Rails and PHP 設定 因為還有引用別人文章 所以就不在這裡提了 http://lightyror.blogspot.com/2006/09/lighttpd-rails-domain_13.html ***警告*** 因為我懶得學 ASCII 所以很多HTML標題效果,我都沒有調整 如果你覺得下面的文章很難看的懂 麻煩請到網頁上面看 *_* 至於這裡的文章僅當作留下紀錄給大家翻閱 ******* 最簡單的方式 其實Rails 自己就有附設定檔,如果你不想自己寫那麼多設定,只想用 lighttpd 跑 Rails 您首先要確定您這個 user 擁有可以使用 lighttpd 的權限 然後在 Rails 資料夾下打 ruby script/server 他應該就會直接使用 lighttpd 下面是啟動 lighttpd 正常的message => Booting lighttpd (use 'script/server webrick' to force WEBrick) => Rails application started on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server (see config/lighttpd.conf for options) 如果出現下面的message,代表只有啟動 Webrick => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options 那通常就是您這個 user 不可以使用 lighttpd 的權限 打入 ruby script/server lighttpd 這個指令強制使用 lighttpd ,用於 Debug 用途 並且會將 lighttpd config copy 一份到rails 資料匣下面的 conf/lighttpd.conf config 預設 port 是 3000,如果你想要直接用 port 80 可以到裡面把改成 server.port = 80 詳細的方式 Var 的部份 var.railsbasedir = '/rails/root/dir/' 這裡是設定 config 檔的變數,以後修改位置改這裡就好了 Server Port的部份 server.bind = "1.2.3.4" server.port = 3000 Server.bind 就是server 的 ip server.port 就是lighttpd listen 的 port Modules 的部份 server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi", "mod_compress", "mod_expire" ) 這裡是相關一定要enable的 Modules 其他設定的部份 # Ruby on Rails Config server.error-handler-404 = "/dispatch.fcgi" server.document-root = var.railsbasedir + "/public/" server.errorlog = var.railsbasedir + "/log/lighttpd.error.log" accesslog.filename = var.railsbasedir + "/log/lighttpd.access.log" url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" ) compress.filetype = ( "text/plain", "text/html", "text/css", "text/javascript" ) compress.cache-dir = var.railsbasedir + "/tmp/cache" expire.url = ( "/favicon.ico" => "access 3 days", "/images/" => "access 3 days", "/stylesheets/" => "access 3 days", "/javascripts/" => "access 3 days" ) fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 3, "socket" => var.railsbasedir + "/tmp/sockets/fcgi.socket", "bin-path" => var.railsbasedir + "/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ) ))) $HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" { server.max-keep-alive-requests = 0 } 有幾個地方可以注意 1. var.railsbasedir的部份只是因為以後搬目錄方便設定,其實那裡都可以用絕對路徑設定 2. "min-procs" => 1, "max-procs" => 3 代表最少fastcgi process 一個,最多三個 3. "bin-environment" => ( "RAILS_ENV" => "development" ) 代表現在 rails 是啟動 development 的環境,可以轉成 production 跟 test Rails + PHP 的 lighttpd 設定檔 Rails 跑在 Lighttpd 上面的設定一向不簡單 尤其是可以同時跑 PHP 跟 Rails 的設定更是麻煩 下面我參考 Rails 內附的 lighttpd 修改出相關的設定檔 我是使用 不同 domain 來區別 fastcgi 的設定 Rails Domain 是 rails.example.com PHP Domain 是 php.example.com Var 的部份 var.railsbasedir = '/rails/root/dir/' Modules 的部份 server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi", "mod_compress", "mod_expire" ) Virtual Host Rails 的部份 $HTTP["host"] == "rails.example.com" { server.error-handler-404 = "/dispatch.fcgi" server.document-root = var.railsbasedir + "/public/" server.errorlog = var.railsbasedir + "/log/lighttpd.error.log" accesslog.filename = var.railsbasedir + "/log/lighttpd.access.log" url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" ) compress.filetype = ( "text/plain", "text/html", "text/css", "text/javascript" ) compress.cache-dir = var.railsbasedir + "/tmp/cache" expire.url = ( "/favicon.ico" => "access 3 days", "/images/" => "access 3 days", "/stylesheets/" => "access 3 days", "/javascripts/" => "access 3 days" ) fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 3, "socket" => var.railsbasedir + "/tmp/sockets/fcgi.socket", "bin-path" => var.railsbasedir + "/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ) } Virtual Host PHP 的部份 $HTTP["host"] == "php.example.com" { # PHP mod_fastcgi config server.document-root = "/php/doc/root/dir" fastcgi.server = ( ".php" => ( "localhost" => ( "host" => "61.218.90.243", "port" => 1026, "bin-path" => "/usr/bin/php-cgi", "min-procs" => 1, "max-procs" => 1, ) ) ) } -- lighty RoR 是一個介紹 lighttpd , SQLite , Ruby and Rails 的 Blog http://lightyror.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.100.104 ※ 編輯: giive 來自: 61.230.100.104 (09/14 08:29) ※ 編輯: giive 來自: 61.230.100.104 (09/14 08:55) ※ 編輯: giive 來自: 61.230.100.104 (09/14 08:58)
文章代碼(AID): #1529w5-p (Ruby)
文章代碼(AID): #1529w5-p (Ruby)