rails中使用grape做api,生产环境用nginx做代理,获取真实的ip

Grape官方网站上给出如下的代码,但我用了nginx代理,接收到的都是127.0.0.1
class API < Grape::API helpers do def logger API.logger end end post '/statuses' do logger.info "#{current_user} has statused" end end

后来打印了header记录发现里面有真实的ip,可以通过headers['X-Forwarded-For'].to_s获取真实的ip。

猜你喜欢

转载自www.cnblogs.com/limx/p/10161806.html
今日推荐