1.配置sidekiq routes
### config/routes.rb require 'sidekiq/web' mount Sidekiq::Web, at: "/sidekiq"
输入http://localhost:3000/sidekiq 可进入管理页面
为了安全,可以给这个页面加上basic验证,在config/initializers/sidekiq_password.rb文件中加入下面代码
####config/initializers/sidekiq_password.rb require 'sidekiq' require 'sidekiq/web' #Basic 认证设定 Sidekiq::Web.use(Rack::Auth::Basic) do |user, password| [user, password] == [ENV['SIDEKIQ_USER'], ENV['SIDEKIQ_PASSWORD']] #环境变化设定 end
使用环境变量设置您的用户名和密码。
如下更改 routes.rb 以在访问 /sidekiq 时使用基本身份验证。
####config/routes.rb require 'sidekiq/web' authenticate :user do #authenticate mount Sidekiq::Web => '/sidekiq' end
自定义认证
class AdminAuthConstraint def matches?(request) return false if request.session[:admin_id].blank? Admin.exists?(request.session[:admin_id]) end end Rails.application.routes.draw do mount Sidekiq::Web => '/sidekiq', constraints: AdminAuthConstraint.new end
标签:web,end,Web,sidekiq,rb,routes,page From: https://www.cnblogs.com/hello-ruby/p/17422502.html