Rubycas-client 是一个用来实现单点登陆的 gem 在 development 下需要在 application.rb 下加入如下几行
require 'casclient'
require 'casclient/frameworks/rails/filter'
CASClient::Frameworks::Rails::Filter.configure(
cas_base_url: "http://somesite.com/cas",
enable_single_sign_out: true
)
这样就可以调用 session[:cas_user] 来获取 CAS 登陆后的信息 在 development 下测试良好,一般来说会自动在/tmp/sessions 下生成一个 session 可是到了生产模式:
I, [2015-06-14T20:57:27.790760 #18180] INFO -- : Filter chain halted as CASClient::Frameworks::Rails::Filter rendered or redirected
I, [2015-06-14T20:57:27.790914 #18180] INFO -- : Completed 302 Found in 3ms (ActiveRecord: 0.0ms)
I, [2015-06-14T20:57:28.270761 #18180] INFO -- : Started GET "/verify?user_id=MQ%3D%3D&ticket=ST-1434286982rQdTPVk-f387GBrQPqs" for 123.112.102.233 at 2015-06-14 20:57:28 +0800
I, [2015-06-14T20:57:28.273099 #18180] INFO -- : Processing by ProfileController#verify_identity as HTML
I, [2015-06-14T20:57:28.273166 #18180] INFO -- : Parameters: {"user_id"=>"MQ==", "ticket"=>"ST-1434286982rQdTPVk-f387GBrQPqs"}
I, [2015-06-14T20:57:29.568797 #18180] INFO -- : Completed 500 Internal Server Error in 1295ms
F, [2015-06-14T20:57:29.573320 #18180] FATAL -- :
Errno::ENOENT (No such file or directory - /home/mo1.0/tmp/sessions/cas_sess.ST-1434286982rQdTPVk-f387GBrQPqs):
/usr/local/rvm/gems/ruby-2.0.0-p643/bundler/gems/rubycas-client-b6692b942f69/lib/casclient/tickets/storage.rb:101:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p643/bundler/gems/rubycas-client-b6692b942f69/lib/casclient/tickets/storage.rb:101:in `new'
/usr/local/rvm/gems/ruby-2.0.0-p643/bundler/gems/rubycas-client-b6692b942f69/lib/casclient/tickets/storage.rb:101:in `store_service_session_lookup'
/usr/local/rvm/gems/ruby-2.0.0-p643/bundler/gems/rubycas-client-b6692b942f69/lib/casclient/frameworks/rails/filter.rb:81:in `filter'
/usr/local/rvm/gems/ruby-2.0.0-p643/bundler/gems/rubycas-client-b6692b942f69/lib/casclient/frameworks/rails/filter.rb:15:in `before'
就有了一些问题,而我自己试了试依然没能解决 以下是 production.rb 配置文件
Rails.application.configure do
config.cache_classes = true
config.cache_store = :redis_store, { :host => "localhost", :port => 6379, :db => 1, :namespace => "mo_production" }
config.eager_load = false
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.debug = true
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
config.log_level = :info
config.assets.precompile += %w(mediaelementplayer.js mediaelementplayer.css home.js waterfall.js)
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
解决方法:
chmod -R u+rwX,go+rX,go-w /tmp
chmod -R u+rwX,go+rX,go-w /home/yourapp/tmp
mkdir /home/yourapp/tmp/sessions
生产模式下没有自动生成 sessions 文件夹,这可能是问题之一 还有读写权限问题,这是问题之二 感谢@billy的热心帮助