简体   繁体   English

在rails 3.2中检查生产模式中的500内部服务器错误

[英]check 500 internal server error in production mode in rails 3.2

I have my app in production mode in my linode account and I get in one page a 500 internal server error the message: 我的应用程序在我的linode帐户中处于生产模式,我在一个页面中得到一个500内部服务器错误消息:

We're sorry, but something went wrong.

However in my development environment works fine this page. 但是在我的开发环境中工作正常。

How can I debug this error? 我该如何调试此错误?

How can I see the error origin in my production mode? 如何在生产模式中查看错误原点

I want that rails show errors in production mode. 我希望rails在生产模式下显示错误。

How can I do it? 我该怎么做?

Thank you! 谢谢!

If you have access to ssh, log in to your server via ssh and go to your rails log directory, which is inside your rails directory. 如果您有权访问ssh,请通过ssh登录到您的服务器并转到rails目录中的rails日志目录。

Once you are there run the command tail production.log . 一旦你在那里运行命令tail production.log If this doesn't give you enough information you can also do a tail -n100 production.log (gives you last hundred lines of the production log). 如果这没有给你足够的信息,你也可以做一个tail -n100 production.log (给你生产日志的最后几百行)。

If you have deployed via heroku, then you can access the logs by running heroku logs in your local console. 如果已通过heroku部署,则可以通过在本地控制台中运行heroku logs来访问日志。 (more information here https://devcenter.heroku.com/articles/logging ) (更多信息请访问https://devcenter.heroku.com/articles/logging

I also find it helpful to use the exception_notification gem https://github.com/rails/exception_notification when running in production, as it emails you a stacktrace when an error occurs. 我还发现在生产中运行时使用exception_notification gem https://github.com/rails/exception_notification很有帮助,因为它会在发生错误时通过电子邮件向您发送堆栈跟踪。 Plenty of others also use Hoptoad (http://hoptoadapp.com/) or Exceptional (http://www.exceptional.io/) however i prefer the simple exception_notification gem. 很多其他人也使用Hoptoad(http://hoptoadapp.com/)或Exceptional(http://www.exceptional.io/)但是我更喜欢简单的exception_notification gem。

Also, in some rare occasions when i can't trace the error as a final measure i sometimes open up port 3000 temporarily on the remote server firewall and cd to the rails project and run rails server production with the log level set to debug in config/environments/production.rb so i can see the error in the console, and then close off the port when i have finished. 此外,在一些罕见的情况下,当我无法追踪错误作为最后的措施时,我有时会在远程服务器防火墙上临时打开端口3000并cd到rails项目并运行rails server production并将日志级别设置为在config中调试/environments/production.rb所以我可以在控制台中看到错误,然后在我完成后关闭端口。

Hope that helps. 希望有所帮助。

tail -n100 production.log

will only show the last 100 lines of the log file. 将仅显示日志文件的最后100行。 Just in case you want to see the log running in real time. 以防您希望实时查看日志。

use this 用这个

tail -1000f log/production.log

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

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