将Rails应用程序更改为生产

将Rails应用程序更改为生产

问题描述:

如何更改Rails应用程序以在生产模式下运行?

How can I change my Rails application to run in production mode? Is there a config file, environment.rb for example, to do that?

如何设置和运行Rails 4应用程序?使用Apache和Phusion Passenger在生产模式下(逐步):

How to setup and run a Rails 4 app in Production mode (step-by-step) using Apache and Phusion Passenger:

通常,您可以输入Rails项目, rails s ,并通过 http://something.com:3000获取应用的开发版本>。生产模式的配置有点棘手。

Normally you would be able to enter your Rails project, rails s, and get a development version of your app at http://something.com:3000. Production mode is a little trickier to configure.

我已经花了一段时间了,所以我想我会为新手写这个(例如作为我自己)。互联网上有一些小调整,他们认为这样做可能会更容易。

I've been messing around with this for a while, so I figured I'd write this up for the newbies (such as myself). There are a few little tweaks which are spread throughout the internet and figured this might be easier.


  1. 请参阅本指南的核心服务器的设置(CentOS 6,但它几乎适用于所有Linux版本): https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app- with-apache-and-passenger-on-centos-6

请确保在设置乘客之后,您已经编辑了 /etc/httpd/conf/httpd.conf 文件来反映您的目录结构。 您想将DocumentRoot指向Rails项目/ public文件夹 httpd.conf 文件中具有以下目录的任何位置: / var / www / html / your_application / public 需要更新,否则一切都会令人沮丧。我对此压力还不够。

Make absolute certain that after Passenger is set up you've edited the /etc/httpd/conf/httpd.conf file to reflect your directory structure. You want to point DocumentRoot to your Rails project /public folder Anywhere in the httpd.conf file that has this sort of dir: /var/www/html/your_application/public needs to be updated or everything will get very frustrating. I cannot stress this enough.

重新引导服务器(或至少重启Apache- service httpd restart

Reboot the server (or Apache at the very least - service httpd restart )

输入您的Rails项目文件夹 / var / www / html / your_application 并开始迁移使用 rake db:migrate 。确保数据库表存在,即使您计划稍后添加表(这也是步骤1的一部分)。

Enter your Rails project folder /var/www/html/your_application and start the migration with rake db:migrate. Make certain that a database table exists, even if you plan on adding tables later (this is also part of step 1).

RAILS_ENV =生产耙密钥-这将创建一个secret_key,您可以将其添加到 config / secrets.yml 中。您可以 将其复制/粘贴到config / secrets.yml中,以使运行正常,尽管我建议您不要这样做。就个人而言,我执行此步骤以确保所有其他功能均正常运行,然后将其更改回并稍后再提供。

RAILS_ENV=production rake secret - this will create a secret_key that you can add to config/secrets.yml . You can copy/paste this into config/secrets.yml for the sake of getting things running, although I'd recommend you don't do this. Personally, I do this step to make sure everything else is working, then change it back and source it later.

RAILS_ENV = production rake db:migrate

RAILS_ENV =生产rake资产:预编译如果您正在提供静态资产。这会将js,css和图像文件推送到 / public 文件夹中。

RAILS_ENV=production rake assets:precompile if you are serving static assets. This will push js, css, image files into the /public folder.

RAILS_ENV =生产轨道s

此时,您的应用应该可以在 http://something.com/任何内容,而不是:3000 。如果没有,请输入 passenger-memory-stats 并查看是否有诸如 908 469.7 MB 90.9 MB的旅客RackApp条目:/ var / www / html / projectname

At this point your app should be available at http://something.com/whatever instead of :3000. If not, passenger-memory-stats and see if there an entry like 908 469.7 MB 90.9 MB Passenger RackApp: /var/www/html/projectname

我可能错过了一些令人发指的事情,但这在过去对我有用。

I've probably missed something heinous, but this has worked for me in the past.