杀死/重试作业时Heroku / Sidekiq错误 - 403禁止 - 攻击被阻止

时间:2017-11-22 05:38:00

标签: ruby-on-rails nginx heroku

我在我的heroku应用程序上使用Sidekiq,当我想要杀死一个作业或重试时,它将导致403禁止页面出错:

WARN -- : attack prevented by Rack::Protection::HttpOrigin

我的heroku应用:http://myapp.herokuapp.com 我的域名不起作用:https://www.myapp.my

在sidekiq documentation中,我发现这可以修复添加到routes.rb的错误,但它没有帮助: Sidekiq :: Web.set:session_secret,Rails.application.secrets [:secret_key_base]

我的session_store.rb文件:

Rails.application.config.session_store :cookie_store, key: '_myapp_session'

我猜ssl存在问题。我为nginx.conf找到this solution但是如何在heroku上设置它以测试这是否有帮助?

proxy_set_header        X-Forwarded-Host 'my-host.com';
proxy_set_header        X-Forwarded-Proto $scheme;

或者其他任何解决方案如何解决403禁用?

编辑:我的路线

  require 'sidekiq/web'

  authenticate :admin do
    mount Sidekiq::Web => '/sidekiq'
  end

它适用于localhost但不适用于生产

编辑#2:如果我关闭https并让我的应用程序在http上,它确实有效,那么如何告诉我的app / sidekiq使用https?

  

proxy_set_header X-Forwarded-Proto $ scheme;

     

这将告诉您的应用程序原始请求进来了   使用https即使从nginx到unicorn的请求是http。

但是如何在heroku上做到这一点?

1 个答案:

答案 0 :(得分:1)

我在heroku上也遇到了同样的问题。

自定义域的解决方案;

  • 您需要在配置文件中强制ssl您的rails应用。因为heroku应用程序对应用程序URL使用默认的https方案。如果不强制执行,它将在转发请求时使用不同的方案。 config/environments/production.rb

    # Force ssl
    config.force_ssl = true
    
  • 如果您在heroku上使用免费的dynos,则不能使用ssl功能,应使用heroku应用程序的URL访问sidekiq Web ui https://your-app.herokuapp.com/sidekiq