无法在生产中调试Sinatra应用程序

时间:2022-06-07 11:03:23

I'm deploying a Sinatra app using passenger. The deployed app is working, but not entirely: some paths work fine, others simply render a blank page. I can't seem to find any major differences between the routes that work and the routes that don't, and I can't seem to track down any errors..

我正在使用乘客部署Sinatra应用程序。已部署的应用程序正在运行,但并非完全有效:某些路径可正常运行,其他路径只是呈现空白页面。我似乎无法找到工作路线和没有工作的路线之间的任何重大差异,我似乎无法追查任何错误..

Handlers

处理程序

I have defined the not_found and error handlers as follows:

我已经定义了not_found和错误处理程序,如下所示:

not_found do
  '404. Bummer!'
end

error do
  'Nasty error: ' + env['sinatra.error'].name
end

These work fine on my local machine, both in development and production, but I never see these come up on the server.

这些在我的本地机器上工作正常,无论是在开发还是生产中,但我从未在服务器上看到这些。

Apache Logs

Apache日志

When I tail Apache's access.log and hit one of the broken paths, I see a 500:

当我拖拽Apache的access.log并点击其中一条破碎的路径时,我看到500:

helpers [27/Oct/2009:15:54:59 -0400] "GET /admin/member_photos/photos HTTP/1.1" 500 20 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3"

rack_hoptoad

rack_hoptoad

I've also installed and configured rack_hoptoad middleware in my config.ru, but no exceptions are making it to hoptoad.

我还在我的config.ru中安装并配置了rack_hoptoad中间件,但没有例外,它正在跳转到hoptoad。

# Send exceptions to hoptoad
require 'rack_hoptoad'
use Rack::HoptoadNotifier, 'MY_API_KEY'

logging

记录

I've set up logging like so..

我已经设置了这样的日志..

set :raise_errors => true
set :logging, true

log = File.new("log/sinatra.log", "a+")
STDOUT.reopen(log)
STDERR.reopen(log)

require 'logger'
configure do
  LOGGER = Logger.new("log/sinatra.log") 
end

helpers do
  def logger
    LOGGER
  end
end

This setup lets me call logger.info within my routes, which works locally and on the server for the working routes, but the broken paths don't get far enough to call logger.info.

这个设置允许我在我的路由中调用logger.info,它在本地和服务器上用于工作路由,但是破坏的路径远远不足以调用logger.info。

What to do?

该怎么办?

Any ideas as to how I can see what's causing the 500 errors? Thanks for any help!

关于如何看到导致500错误的原因的任何想法?谢谢你的帮助!

3 个解决方案

#1


6  

I would try using the Rack::ShowExceptions middleware to try and trace out the problem. In your config.ru add these two lines before the run call:

我会尝试使用Rack :: ShowExceptions中间件来尝试找出问题所在。在你的config.ru中,在运行调用之前添加这两行:

require 'rubygems'
require 'your-app'

use Rack::ShowExceptions

run YourApp

That should catch and display the backtrace for any exceptions occurring in Rack or in your app. That should give you more details to work with, at least that would be the hope.

这应该捕获并显示Rack或您的应用中发生的任何异常的回溯。这应该会给你更多的细节,至少这将是希望。

#2


1  

Maybe there's something wrong with your log setup?

也许您的日志设置有问题?

Redirect STDERR when running the Sinatra server so you can read it. Like:

运行Sinatra服务器时重定向STDERR,以便您可以读取它。喜欢:

ruby myapp.rb -p 1234 > log/app.log 2>&1

#3


0  

Thanks for the responses, but I didn't end up needing to use them. I was originally deploying the app in a sub-URI configuration. When I deployed the app to it's own subdomain instead, the problems went away.

感谢您的回复,但我最终还是不需要使用它们。我最初是在子URI配置中部署应用程序。当我将应用程序部署到它自己的子域时,问题就消失了。

So.. I'm not really sure what the problem was, but getting rid of this line is my Apache configuration for the site is what resolved things:

所以..我不是很确定问题是什么,但摆脱这一行是我的网站的Apache配置是什么解决的事情:

Redirect permanent / https://www.example.org/admin/member_photos/

#1


6  

I would try using the Rack::ShowExceptions middleware to try and trace out the problem. In your config.ru add these two lines before the run call:

我会尝试使用Rack :: ShowExceptions中间件来尝试找出问题所在。在你的config.ru中,在运行调用之前添加这两行:

require 'rubygems'
require 'your-app'

use Rack::ShowExceptions

run YourApp

That should catch and display the backtrace for any exceptions occurring in Rack or in your app. That should give you more details to work with, at least that would be the hope.

这应该捕获并显示Rack或您的应用中发生的任何异常的回溯。这应该会给你更多的细节,至少这将是希望。

#2


1  

Maybe there's something wrong with your log setup?

也许您的日志设置有问题?

Redirect STDERR when running the Sinatra server so you can read it. Like:

运行Sinatra服务器时重定向STDERR,以便您可以读取它。喜欢:

ruby myapp.rb -p 1234 > log/app.log 2>&1

#3


0  

Thanks for the responses, but I didn't end up needing to use them. I was originally deploying the app in a sub-URI configuration. When I deployed the app to it's own subdomain instead, the problems went away.

感谢您的回复,但我最终还是不需要使用它们。我最初是在子URI配置中部署应用程序。当我将应用程序部署到它自己的子域时,问题就消失了。

So.. I'm not really sure what the problem was, but getting rid of this line is my Apache configuration for the site is what resolved things:

所以..我不是很确定问题是什么,但摆脱这一行是我的网站的Apache配置是什么解决的事情:

Redirect permanent / https://www.example.org/admin/member_photos/