如何在 Windows 中为 Ruby on Rails 配置 Apache 2.2?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/148838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:41:41  来源:igfitidea点击:

How do I configure Apache 2.2 for Ruby on Rails in Windows?

ruby-on-railsrubyapache

提问by Owen

I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails.

我正在尝试开始编写一些 Ruby on Rails 应用程序,并在 Mongrel 上取得了成功,但是,我想将我的应用程序部署到 Windows 上的 Apache 2.2 实例?我发现的所有教程似乎都过时了,并且适用于旧版本的 Apache/Rails。

Does anyone know of a good, current tutorial for configuring Apache 2.2 for Ruby on Rails apps?

有谁知道为 Ruby on Rails 应用程序配置 Apache 2.2 的一个很好的当前教程?

回答by Dave Nolan

EDIT:At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can use Apache + FastCGI without Mongrel, but under real loads you will get (more) zombie processes and (more) memory leaks.

编辑:至少在有 Win 的 Phusion 乘客之前,Apache + Mongrel 是要走的路。您可以在没有 Mongrel 的情况下使用 Apache + FastCGI,但在实际负载下,您将获得(更多)僵尸进程和(更多)内存泄漏。

You could also look at proxying to Thinin the same way as detailed below. However, I've had some instabilities with Thin on Win, even though it's appreciably quicker. AB (Apache Benchmark) is your friend here!

您还可以按照下面详述的相同方式查看代理到Thin。但是,我在使用 Thin on Win 时遇到了一些不稳定性,尽管它明显更快。AB (Apache Benchmark) 是您的朋友!

Configuring Apache + Mongrel on Windows is not significantly different from *nix.

在 Windows 上配置 Apache + Mongrel 与 *nix 没有太大区别。

Essentially, you need to proxy requests coming into Apache to Mongrel. What this boils down to is something like this:

本质上,您需要将进入 Apache 的请求代理到 Mongrel。这归结为是这样的:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
    ServerName www.myapp.comm
    DocumentRoot "C:/web/myapp/public"
    ProxyPass / http://www.myapp.com:3000/
    ProxyPassReverse / http://www.myapp.com:3000/
    ProxyPreserveHost On
</VirtualHost>

Stick this in your httpd.conf(or httpd-vhost.confif you're including it).

把它放在你的httpd.conf(或者httpd-vhost.conf如果你包括它)中。

It assumes you're going to run mongrel on port 3000, your Rails root is in C:\web\myapp, and you'll access the app at www.myapp.com.

它假设您将在端口 3000 上运行 mongrel,您的 Rails 根在 中C:\web\myapp,并且您将在 www.myapp.com 上访问该应用程序。

To run the rails app in production mode:

在生产模式下运行 rails 应用程序:

mongrel_rails start -p 3000 -e production

And away you go (actually mongrel defaults to port 3000 so you could skip -p 3000if you want).

然后你就走了(实际上,mongrel 默认使用端口 3000,所以你可以-p 3000根据需要跳过)。

The main difference is that you cannot daemonize mongrel on Windows (i.e. make it run in the background). Instead you can install it as a service using the mongrel_servicegem.

主要区别在于您不能在 Windows 上守护 mongrel(即让它在后台运行)。相反,您可以使用mongrel_servicegem将其安装为服务。

Also, running a cluster is more complicated and you won't be able to use Capistrano. Let me know if you want more info.

此外,运行集群更复杂,您将无法使用 Capistrano。如果您需要更多信息,请告诉我。

回答by danny

I'm new to RoR and have been attempting the same thing on Windows Server 2008, here are some additional notes on getting mongrel going as a service:

我是 RoR 的新手并且一直在 Windows Server 2008 上尝试同样的事情,这里有一些关于让 mongrel 作为服务运行的附加说明:

if you get compilation errors when installing mongrel_service:

如果在安装 mongrel_service 时遇到编译错误:

gem install mongrel_service

try using a binary instead by specifying your platform:

尝试通过指定您的平台来使用二进制文件:

gem install mongrel_service --platform x86-mswin32

Additionally, to actually install the service you need to run this command in your RoR's app directory:

此外,要实际安装服务,您需要在 RoR 的应用程序目录中运行此命令:

mongrel_rails service::install --name MyApp -e production -p 3001 -a 0.0.0.0

(or to remove:

(或删除:

mongrel_rails service::remove --name MyApp

)

)

Then you should be able to start/stop the app "MyApp" in your windows services control panel.

然后您应该能够在您的 Windows 服务控制面板中启动/停止应用程序“MyApp”。

Hope that helps someone.

希望能帮助某人。

回答by muloka

At the moment Mongrel does not work properly with Ruby 1.9 and will throw a "msvcrt-ruby18.dll not found" error when executing the command mongrel_rails.

目前,Mongrel 不能在 Ruby 1.9 中正常工作,并且在执行命令 mongrel_rails 时会抛出“msvcrt-ruby18.dll not found”错误。

Thin in this case seems to be the only option for now.

在这种情况下,瘦似乎是目前唯一的选择。

回答by aviemet

I just wanted to add this article to the list. It explains how to have Apache serve ruby files without the need to install any other applications.

我只是想将这篇文章添加到列表中。它解释了如何让 Apache 提供 ruby​​ 文件而无需安装任何其他应用程序。

http://editrocket.com/articles/ruby_apache_windows.html

http://editrocket.com/articles/ruby_apache_windows.html

回答by Kokizzu

You might want to try Bitnami RubyStack

你可能想尝试Bitnami RubyStack