部署 rails + apache + fcgi

asmcos · 2013年03月26日 · 3120 次阅读

我使用的是 VPS(ubuntu 12.04),上面有 php,python。 为了将 rails 项目部署到服务器上,我选择了 fcgi。

  1. 安装软件如下:
sudo aptitude install libapache2-mod-fcgid libfcgi-ruby1.9.1
  1. enable apache 的 rewrite
a2enmod rewrite
  1. apache config

vim /etc/apache2/sites-enabled/codepark.conf

<VirtualHost *:80>
   DefaultInitEnv RAILS_ENV development
   DocumentRoot /home/xxxxx/public
   ServerName www.codepark.us
   <Directory />
   AllowOverride All
   Options ExecCGI FollowSymLinks
   AllowOverride all
   Order allow,deny
   Allow from all
   </Directory>
</VirtualHost>


  1. public 目录 .htaccess
SetEnv RAILS_RELATIVE_URL_ROOT /xxxxx

RewriteEngine On


RewriteRule ^(.*)$ xxxxxx_cgi.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]

xxxxxx_cgi.fcgi

#!/usr/bin/ruby

require_relative '../config/environment'

class Rack::PathInfoRewriter
  def initialize(app)
    @app = app
  end

  def call(env)
    env.delete('SCRIPT_NAME')
    parts = env['REQUEST_URI'].split('?')
    env['PATH_INFO'] = parts[0]
    env['QUERY_STRING'] = parts[1].to_s
    @app.call(env)
  end
end

Rack::Handler::FastCGI.run  Rack::PathInfoRewriter.new(Xxxxx::Application)


暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号