简体   繁体   English

运行Rails站点:开发与生产

[英]Running a Rails site: development vs production

I'm learning Ruby on Rails. 我正在学习Ruby on Rails。 At the moment I'm just running my site locally with rails server in the OS X Terminal. 目前我只是在OS X终端中使用rails server在本地运行我的站点。 What changes when a Rails site is run on a production box? 在生产箱上运行Rails站点时会发生什么变化?

  • Is the site still started with rails server ? 该网站是否仍以rails server启动?
  • Any differences with how the db is setup? 与db的设置有何不同?

Note : I'm running Rails 3. 注意 :我正在运行Rails 3。

A rails app can be run in production calling rails server -e production , although 99% of the time you'll be serving on something like passenger or thin instead of WEBrick, which means there's a different command to start the server. rails应用程序可以在生产中运行,调用rails server -e production ,尽管99%的时间你将用于乘客或瘦身而不是WEBrick,这意味着有一个不同的命令来启动服务器。 ( thin start -e production for instance) (例如, thin start -e production

This is a complicated question, but the best place to start learning about the differences would be to look at the specific environment.rb files. 这是一个复杂的问题,但是开始了解差异的最佳位置是查看特定的environment.rb文件。 When rails boots up it starts with the environment file that matches the called environment, ie if you start it in development it begins by loading your development.rb file, or if you're in production it will load the production.rb file. 当rails启动时,它会从与被调用环境匹配的环境文件开始,即如果您在开发中启动它,则首先加载您的development.rb文件,或者如果您正在生产它将加载production.rb文件。 The differences in environments are mostly the result of these differences in the various environment config files. 环境的差异主要是各种环境配置文件中这些差异的结果。

Basically if a Rails 3.1 app is in production mode, then by default it is not going to be compiling assets on the fly, and a lot of caching will be going on that isn't happening in development. 基本上,如果Rails 3.1应用程序处于生产模式,那么默认情况下它不会动态编译资产,并且许多缓存将继续进行,而这在开发中是不会发生的。 Also, when you get error messages they will be logged but not rendered to the user, instead the static error page from your public directory will be used. 此外,当您收到错误消息时,它们将被记录但不会呈现给用户,而是使用公共目录中的静态错误页面。

To get more insight into this, I would suggest reading the relevant rails guides: 为了更深入地了解这一点,我建议您阅读相关的rails指南:

Rails Initialization Guide: http://guides.rubyonrails.org/initialization.html Rails初始化指南: http//guides.rubyonrails.org/initialization.html

Rails Configuration Guide: http://guides.rubyonrails.org/configuring.html Rails配置指南: http//guides.rubyonrails.org/configuring.html

There are two contexts you can use the word "production" here. 有两种情况你可以在这里使用“生产”这个词。 One of them is running the server in production mode. 其中一个是在生产模式下运行服务器。 You can do this locally by, 你可以在当地这样做,

RAILS_ENV=production ./script/server 

The configuration for this is picked up from config/environments/production.rb. 从config / environments / production.rb中获取此配置。 Try comparing this file with config/environments/development.rb. 尝试将此文件与config / environments / development.rb进行比较。 There are only subtle differences like caching classes. 只有缓存类之类的细微差别。 Development mode makes it easier so that it will respond to any changes you make instantly. 开发模式使其更容易,以便它可以立即响应您所做的任何更改。 Plus there are two different databases (by default) will be used namely yourproject_development and yourproject_production if you choose to run your server in either of these modes. 此外,如果您选择以这两种模式之一运行服务器,则将使用两个不同的数据库(默认情况下),即yourproject_development和yourproject_production。

On the other hand, rails deployment to a production box is something different. 另一方面,将轨道部署到生产箱是不同的。 You will need to pick your server carefully. 您需要仔细选择服务器。 You may have to deal with a deployment script may be capistrano. 您可能必须处理部署脚本可能是capistrano。 You may also need a load balancer such as netgear. 您可能还需要负载均衡器,例如netgear。 The database also may require a deep consideration like size expectation, master/slave clustering etc., 数据库也可能需要深入考虑,如大小期望,主/从群集等,

Note: I have never used Rails 3. This answer is biased towards 2.3.x. 注意:我从未使用过Rails 3.这个答案偏向于2.3.x.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM