简体   繁体   English

Rails应用程序在开发中有效,但在生产中为空

[英]Rails application works in development but is empty in production

My Rails 4 application runs in development mode, but at production I only see an empty page. 我的Rails 4应用程序在开发模式下运行,但是在生产环境中,我只会看到一个空白页面。

It's running Unicorn with Nginx in a CentOS 7 VPS. 它在CentOS 7 VPS中与Nginx一起运行Unicorn。

Any hint what I need? 任何提示我需要什么?

unicorn_rails -c config/unicorn.rb -D

Rails开发

unicorn_rails -c config/unicorn.rb -D -E production

轨道生产

The logs of Nginx, Unicorn and Rails don't show any errors. Nginx,Unicorn和Rails的日志未显示任何错误。

Rake routes 耙线
[root@mycentos my_app]# rake routes [root @ mycentos my_app]#耙路

   Prefix Verb   URI Pattern               Controller#Action
    blogs GET    /blogs(.:format)          blogs#index
          POST   /blogs(.:format)          blogs#create
 new_blog GET    /blogs/new(.:format)      blogs#new
edit_blog GET    /blogs/:id/edit(.:format) blogs#edit
     blog GET    /blogs/:id(.:format)      blogs#show
          PATCH  /blogs/:id(.:format)      blogs#update
          PUT    /blogs/:id(.:format)      blogs#update
          DELETE /blogs/:id(.:format)      blogs#destroy

In development I can access normally to any route, even it shows me error messages when the route doesn't exist. 在开发中,我可以正常访问任何路由,即使在不存在该路由时也会显示错误消息。 But in production, is always blank. 但是在生产中,始终是空白。 在开发中运作良好-在生产中始终空白

I'm not so boldly switching over to the answer area here, but it's time. 我不是在这里大胆地切换到答案区域,但是是时候了。 I know that node.js can be used to create a single page app on Rails. 我知道node.js可用于在Rails上创建单页应用程序。 It's something I want to try, but haven't done, yet. 我想尝试一下,但还没有完成。

Before diving into an isolate and conquer scenario, have you looked at your production log. 在深入探讨孤立与征服场景之前,您是否已查看过生产日志。 It will probably be stacked up with errors. 它可能会堆满错误。 Do they tell you anything? 他们有告诉你什么吗?

I approach this not knowing exactly the complexion of the problem. 我无法确切知道问题的复杂性。 And, I don't know what you've already tried. 而且,我不知道您已经尝试过什么。 But, I would try to isolate the problem by removing components and complexity. 但是,我将尝试通过消除组件和复杂性来隔离问题。 I suggest creating a very simple "Hello world" page at the root. 我建议在根目录创建一个非常简单的“ Hello world”页面。 That's it. 而已。 If we can resolve this and get something to deploy, then you can progress. 如果我们可以解决此问题并进行部署,那么您可以继续进行。

Getting a "Hello world!" 获得一个“ Hello world!” page will prove your MVC code base setup and deploy are functioning. 页面将证明您的MVC代码库设置和部署正常运行。 And you isolate the database out as a variable in production. 然后将数据库隔离为生产中的变量。

Hello world! 你好,世界! Simple test - I have not seen a Rails app which did not require a root_url. 简单测试 -我还没有看到不需要root_url的Rails应用。 (maybe node.js setup does not req. one? Dunno.) In your routes.db add (也许node.js的设置不要求一个?Dunno。)在您的route.db中添加

  root 'static_pages#home'

Rake in and make sure the path shows up. 进入并确保显示路径。 Create an home.html.erb in /static pages that has html for "Hello World." 在/ static页面中创建一个具有html的“ Hello World”的home.html.erb。 Deploy + test to dev + prod using the same command you've been using: 使用您一直在使用的相同命令将+ +测试部署到dev + prod:

unicorn_rails -c config/unicorn.rb -D -E production

If working, then you know that your deploy works, If not working in production, then remove another component... 如果可以正常工作,那么您就知道您的部署可以正常工作;如果不能在生产环境中工作,则可以删除另一个组件...

Unplug Node.js 拔下Node.js

In your simple "Hello Page" world app, you don't need node.js. 在简单的“ Hello Page”世界应用程序中,您不需要node.js。 If you are 100% confident it can't be introducing the problem, then disregard this advice. 如果您100%确信它不会引起问题,请忽略此建议。

Hello world, Still not working without database and without node.js? 世界,您好,如果没有数据库和node.js,仍然无法正常工作吗? Look at production parameters, Gemfile, etc. I'll add detail here if needed. 查看生产参数,Gemfile等 。如果需要我将在此处添加详细信息。 Although I hope the problem isn't in the environments/production.rb...but it could be. 虽然我希望问题不在环境/production.rb中,但是可能是。


It would seem like someone with Rails exp. 似乎有人使用Rails exp。 on node.js would be better to answer this question, but since no one else is stepping up, I hope my input is of some help, if only to see the problem in another way. 在node.js上更好地回答这个问题,但是由于没有其他人在加强,所以我希望我的输入对您有所帮助,即使只是以另一种方式查看问题。

After investigating a lot, the problem was that there wasn't the secret key for production. 经过大量调查后,问题在于没有生产用的秘密钥匙。 So I had to generate it running rake secret and pasting it in config/secrets.yml . 所以我必须运行rake secret来生成它并将其粘贴到config/secrets.yml

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

相关问题 在 Rails 6 中:视差在开发中有效但不在生产中 - In Rails 6: Parallax works in development but not in production Rails代码在开发中有效,但在生产中无效 - Rails code works in development but not in production Rails 5 CarrierWave Gem在生产中工作但不在开发中 - Rails 5 CarrierWave Gem Works in Production But Not In Development Rails:检测用户代理是否在开发中工作但不在生产中? - Rails: Detecting user agent works in development but not production? Rails 4-服务器在开发模式下工作,但不在生产模式下工作 - Rails 4 - server works in development mode, but not in production Rails Ajax Spinner正在开发中,但未在生产中工作 - rails ajax spinner works in development but not production 方法在开发中有效,但在生产中不起作用Rails MongoDB - Method works in development but not production Rails MongoDB Rails 3:caches_page在开发中起作用,而不在生产中起作用 - Rails 3: caches_page works in development and not in production Rails Log Formatter在开发中可用,但不能在生产中使用 - Rails Log Formatter works in Development, but not Production 应用程序在开发模式下工作,但不在生产模式下 - Application works in development mode but not in production mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM