部署 nginx+passenger 部署 rails3.0 ruby1.9 不知道怎么从 development 切到 production 模式

cyrusinshanghai · 2013年07月01日 · 最后由 akmumu 回复于 2014年11月21日 · 4214 次阅读

各位大侠: 我新安装了 nginx+passenger,默认的是 development 模式,网站运行正常,但是 CPU 跑高的厉害,手上没有资料,不知道怎么切换到 production 模式。

还望高手们支招,如果能写一下详细的步骤,小弟不胜感激啊啊啊啊啊!!!

passenger 默认是 production,除非你在 nginx 的配置文件里面设置了 rails_env 这个参数为 development,检查一下配置文件吧

哦哦,我安装之后,在 server 里面写了设置 rails_env 为 development,是从一个资料里面看的,然后我把它修改为 rails_env 为 production,没法访问网站了

server {
    ...
    passenger_enabled on;
    rails_env production;
}

#3 楼 @ashchan 嗯嗯 这个我做了 然后 rails_env production;就没法访问网站了

#1 楼 @quakewang 原来不用设置 rails_env 就是 production 了。非常感谢,但是我添加了 rails_env production,没法访问了!~

是不是 rails 那边要 production 需要敲一些命令啊??

rails3 production 下需要 rake assets:precompile

#6 楼 @ZombieCoder 我按照这个步骤做了,还是打不开,不过我看到了 log 里面有写,是因为一个 js 没有预编译。请问如果我单独写一个 js 文件,怎么能够编译呢? 我的 Log 如下:

Processing by MainPageController#index as HTML Rendered main_page/index.html.erb within layouts/application (24.5ms) Completed 500 Internal Server Error in 76ms

ActionView::Template::Error (bigbanner.js isn't precompiled): 4:

鏄淇℃伅 5: <%= stylesheet_link_tag "application", :media => "all" %> 6: <%= javascript_include_tag "application" %> 7: <%= javascript_include_tag "bigbanner" %> 8: <%= javascript_include_tag "news" %> 9: <%= csrf_meta_tags %> 10: app/views/layouts/application.html.erb:7:in `app_views_layouts_application_html_erb_3036974846057913139_38240960'

shell:/opt/wwwroot/demo_v2/app/assets/javascripts$ ls application.js inner.js.coffee lv2s.js.coffee lv4s.js.coffee news.js bigbanner.js lv1s.js.coffee lv3s.js.coffee main_page.js.coffee 我在 javascripts 里面是这么加入 js 的

独立链接的 assets 要加到 precompile 的选项里面 http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

config.assets.precompile += ['bigbanner.js', 'news.js']

啊,看起来可以了~ 谢谢楼上各位。我总结一下: 使用 nginx+passenger 部署 rails 1、默认为 production 模式 2、在部署前要在 rails 工程目录下运行 rake assets:precompile RAILS_ENV=production 另外:如果有一些独立链接,需要在 config/environments/目录下的 production.rb 文件中添加如: config.assets.precompile += ['bigbanner.js', 'news.js'] 的语句,加入到 precompile 中

再次谢谢各位的热心~

可以使用rake secret自己算一个出来放在 config/secret.yml 里面

需要 登录 后方可回复, 如果你还没有账号请 注册新账号