Ruby + Apache+ mod_fcigd 配置笔记
因为公司不想用别的WEB服务器,所以只能把Ruby源码发布到现有的Apache上,弄了半天终于搞定,留个笔记,供大家参考。安装环境 Linux CentOs5, Apache 2.2.9, Ruby 1.86, Rails 2.1.0. gem 1.2.0
使用的模块是 : fast cgi , mod_fcgid.
为什么使用mod_fcgid 请看 http://fastcgi.coremail.cn/index.htm
1. 下载所需文件源码
wgethttp://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
wgethttp://nchc.dl.sourceforge.net/sourceforge/mod-fcgid/mod_fcgid.2.2.tgz
2. 编译安装 fcgi
tar -zxvffcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
make install
3. 编译安装 mod_fcgid模块
tar -zxvf mod_fcgid.2.2.tgz
cd mod_fcgid.2.2
注意:如果 apache 没有安装在 /usr/local/apache2 修改 mod_fcgid.2.2文件夹里的
top_dir 为现在apache的路径,同时这里还需要apachesrc和build路径,建议都放到一起,这样改动比较少,
也不容易出错.
make
make install
完成后没有错误的话 mod_fcgid.so 文件会自动拷贝到 apache/ modules/ 目录下.
4. 安装 fcgi gem
gem install fcgi
如果错误提示:can’t find header files for ruby , 需要安装 ruby-devel 包.
5. apache 配置
在 httpd.conf 里添加下面的代码
LoadModule fcgid_module modules/mod_fcgid.so
SocketPath /tmp/fcgidsock
DefaultInitEnv RAILS_ENV production
<Directory /htdocs/railsproject/public>
Options ExecCGI FollowSymLinks
AllowOverride AuthConfig Indexes Limit
Order allow,deny
Allow from all
AddHandler fcgid-script .fcgi
# You need mod_fcgid version >= 2.1 to support arguments "xxx/dispatch.fcgi" in FCGIWrapper
FCGIWrapper "/htdocs/railsproject/public/dispatch.fcgi" .fcgi
RewriteEngine On
RewriteRule ^$ index.html
RewriteRule ^([^.]+)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi
</Directory>
ok ,重启apache 后就可以在 http://yourdomain/railsproject/public/ 里访问到了,这样的url 虽然很不好看,但目的已经达到了,需要的同学可以自己加vhost.
参考资料:
HowtoSetupApacheWithFastCGIAndRubyBindings
页:
[1]