百度空间 | 百度首页 
 
查看文章
 
Rails 在服务器上的部署
2007-05-21 17:50


通常来说,比较一下上面的表格,我们会很自然地选择lighttpd-fcgi这种方案来部署我们的应用。

接下来我们给出Rails应用在Linux服务器上部署的基本过程:

  • 所需要的软件包:
    • lighttpd-1.4.10.tar.gz
    • fcgi-2.4.0.tar.gz
    • ruby-1.8.4.tar.gz
    • rubygems-0.8.11.tgz
    • ruby-fcgi-0.8.6.tgz
安装步骤:
  • 安装Ruby
  • 安装rubygems
  • 安装ruby-fcgi
  • 安装rails,用命令行命令 gem install rails
  • 安装lighttpd(创建用户www和组www, 创建目录/var/lighty作为文档根目录, /var/lighty/logs作为日志目录)
  • 最关键的步骤:在lighttpd的配置文件(默认是/etc/lighttpd/lighttpd.conf)中配置rails应用支持。这里 给出一个配置文件的完整例子(用Virtual host 方式配置,容易支持一个主机上多个rails应用):更详细的信息可以参考这里
    # lighttpd configuration file
    #
    # use it as a base for lighttpd 1.0.0 and above
    #
    # $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $

    ############ Options you really have to take care of ####################

    server.modules = (
    “mod_rewrite”,
    “mod_access”,
    “mod_fastcgi”,
    “mod_simple_vhost”,
    “mod_evhost”,
    “mod_accesslog” )

    ## a static document-root, for virtual-hosting take look at the
    ## server.virtual-* options
    server.document-root = “/var/lighty/cartrain/public”

    ## where to send error-messages to
    server.errorlog = “/var/lighty/logs/lighttpd.error.log”

    # files to check for if …/ is requested
    #index-file.names = ( “index.php”, “index.html”,
    # “index.htm”, “default.htm” )

    ## set the event-handler (read the performance section in the manual)
    # server.event-handler = “freebsd-kqueue” # needed on OS X

    # mimetype mapping
    mimetype.assign = (
    “.pdf” => “application/pdf”,
    “.sig” => “application/pgp-signature”,
    “.spl” => “application/futuresplash”,
    “.class” => “application/octet-stream”,
    “.ps” => “application/postscript”,
    “.torrent” => “application/x-bittorrent”,
    “.dvi” => “application/x-dvi”,
    “.gz” => “application/x-gzip”,
    “.pac” => “application/x-ns-proxy-autoconfig”,
    “.swf” => “application/x-shockwave-flash”,
    “.tar.gz” => “application/x-tgz”,
    “.tgz” => “application/x-tgz”,
    “.tar” => “application/x-tar”,
    “.zip” => “application/zip”,
    “.mp3″ => “audio/mpeg”,
    “.m3u” => “audio/x-mpegurl”,
    “.wma” => “audio/x-ms-wma”,
    “.wax” => “audio/x-ms-wax”,
    “.ogg” => “application/ogg”,
    “.wav” => “audio/x-wav”,
    “.gif” => “image/gif”,
    “.jpg” => “image/jpeg”,
    “.jpeg” => “image/jpeg”,
    “.png” => “image/png”,
    “.xbm” => “image/x-xbitmap”,
    “.xpm” => “image/x-xpixmap”,
    “.xwd” => “image/x-xwindowdump”,
    “.css” => “text/css”,
    “.html” => “text/html”,
    “.htm” => “text/html”,
    “.js” => “text/javascript”,
    “.asc” => “text/plain”,
    “.c” => “text/plain”,
    “.cpp” => “text/plain”,
    “.log” => “text/plain”,
    “.conf” => “text/plain”,
    “.text” => “text/plain”,
    “.txt” => “text/plain”,
    “.dtd” => “text/xml”,
    “.xml” => “text/xml”,
    “.mpeg” => “video/mpeg”,
    “.mpg” => “video/mpeg”,
    “.mov” => “video/quicktime”,
    “.qt” => “video/quicktime”,
    “.avi” => “video/x-msvideo”,
    “.asf” => “video/x-ms-asf”,
    “.asx” => “video/x-ms-asf”,
    “.wmv” => “video/x-ms-wmv”,
    “.bz2″ => “application/x-bzip”,
    “.tbz” => “application/x-bzip-compressed-tar”,
    “.tar.bz2″ => “application/x-bzip-compressed-tar”
    )

    # Use the “Content-Type” extended attribute to obtain mime type if possible
    #mimetype.use-xattr = “enable”

    ## send a different Server: header
    ## be nice and keep it at lighttpd
    # server.tag = “lighttpd”

    #### accesslog module
    accesslog.filename = “/var/lighty/logs/access.log”

    ## deny access the file-extensions
    #
    # ~ is for backupfiles from vi, emacs, joe, …
    # .inc is often used for code includes which should in general not be part
    # of the document-root
    url.access-deny = ( “~”, “.inc” )

    $HTTP[”url”] =~ “\.pdf$” {
    server.range-requests = “disable”
    }

    ##
    # which extensions should not be handle via static-file transfer
    #
    # .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
    static-file.exclude-extensions = ( “.php”, “.pl”, “.fcgi” )

    ######### Options that are good to be but not neccesary to be changed #######

    ## bind to port (default: 80)
    server.port = 80

    var.osapp = “www.xxx.com”
    $HTTP[”host”] == “cu.ttthree.com”{
    server.document-root = var.osapp + “/public”
    server.error-handler-404=”/dispatch.fcgi”
    fastcgi.server =
    ( “.fcgi” =>
    ( “localhost” =>
    ( “min-procs” => 2,
    “max-procs” => 2,
    “socket” => “/tmp/mycoolapp.fcgi.socket”,
    “bin-path” => var.osapp+ “/public/dispatch.fcgi”,
    “bin-environment” => ( “RAILS_ENV” => “development” )
    )
    )
    )
    }

    url.rewrite = (
    “^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9%]+)\??([\-_a-zA-Z0-9=&%]*)$” =>
    “/dispatch.fcgi?controller=$1&action=$2&id=$3&$4″,
    “^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$” =>
    “/dispatch.fcgi?controller=$1&action=$2&$3″,
    “^/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$” =>
    “/dispatch.fcgi?controller=$1&action=index&$2″
    )


类别:Ruby On Rails | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu