有没有什么好方法可以在 Windows 机器上使用 Apache 部署基于 Ruby 1.9.3 和 Rails 3.2.6 构建的 Ruby on Rails 应用程序?我花了几个小时在论坛上搜索,但所有的帖子似乎都太旧了,无法使用最新版本的 Ruby 和 Rails。 Mongrel 不再处于开发阶段并不断导致 Rails 崩溃,thin 只支持基本的 Windows 并且在我的电脑上导致 Ruby 运行时“以一种不寻常的方式自行终止”,Passenger 只支持 Linux ......我有点迷茫这一点。
是否有任何稳定的、有据可查的解决方案来为基于 Windows 上的 Apache 的最新框架构建的 Rails 应用程序提供服务?
更新
我最终得出了自己的解决方案。在下面查看有关在 Windows 上部署 Rails 的最新指南。
最佳答案
更新:我刚刚回到部署此流程的公司。在产品使用期间完全没有维护 11 个月后,应用程序和服务器环境仍然可以完美运行:)
好吧,看来我终于想通了。请注意,我正在部署到公司 Intranet 上的一小部分用户,因此我的解决方案可能不适用于所有人。我正在使用优秀的Bitnami RubyStack ,其中包含一个集成的 Apache/Rails/MySQL 安装。从那里我做了以下(适用于 Rails 3.2.6 和 Ruby 1.9.3):
bundle exec rake db:migrate db:schema:load RAILS_ENV="production"
.警告:db:schema:load 将删除生产数据库中的所有数据。 bundle exec rake assets:precompile
.请注意,这可能需要很长时间,具体取决于您的 Assets 。 httpd.conf
(对我来说是 C:\RubyStack-3.2.5-0\apache2\conf\httpd.conf)确保没有注释掉必要的模块:
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
然后将以下代码粘贴到文件中的某处,使用
app_name
是 Rails 应用程序的文件夹名称和 *:82
是 Apache 正在监听的任何端口号(由命令 Listen <port_number>
表示:<VirtualHost *:82>
# Your server's web or IP address goes here.
# You can leave at localhost if deploying to
# company intranet or some such thing.
ServerName localhost
# Customize the next two lines with your app's public directory
DocumentRoot "C:/RubyStack-3.2.5-0/projects/app_name/public"
<Directory "C:/RubyStack-3.2.5-0/projects/app_name/public">
Allow from all
Options -MultiViews
</Directory>
RewriteEngine On
# Redirect all non-static requests to Rails server,
# but serve static assets via Apache
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://app_balancers%{REQUEST_URI} [P,QSA,L]
# Serves dynamic rails assets from multiple servers
# to improve performance. A Rails server such as
# thin or WEBrick must be running on at least one of
# these ports in order for Apache to serve your site
<Proxy balancer://app_balancers>
BalancerMember http://localhost:3001/
BalancerMember http://localhost:3002/
</Proxy>
# Support for far-futures expires header
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
</VirtualHost>
@echo off
cd D:\your_app_folder
rails s -e production -p 3001
nssm install <servicename>
,其中 <servicename>
是您希望您的服务被调用的任何内容。系统将提示您输入要作为服务运行的应用程序的路径;选择您在步骤 7 中创建的 Windows EXE,然后单击安装,将命令行选项留空。 localhost:82
,如果您自定义它,请将您的端口号替换为 82。您应该会看到您的网站看起来与开发时完全一样。 如果这太长而不适合 StackOverflow,请告诉我。我刚刚花了很多时间来解决这个问题,并认为是时候有人写一篇关于在 Windows 上部署 Rails 的最新指南了(如果有的话,我还没有看过)。祝你好运,如果有人对此有问题或改进,请告诉我!
关于ruby-on-rails - Windows 上的 Rails 部署环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11252199/