環境
aws ec2
nginxの80番ポートで受けてlocalhostの8080番ポートで起動してるrailsにリバースプロキシ

ローカルではfacebookログインでログインできてたのに、サンドボックスに上げたら
{
"error": {
"message": "Invalid redirect_uri: \u6307\u5b9a\u3055\u308c\u305fURL\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3067\u8a31\u53ef\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002",
"type": "OAuthException",
"code": 191
}
}
ってのが延々と繰り返されたわけで・・・
Invalid redirect_uri って書いてあるくらいだからredirect_uriがおかしいんだけど、redirect_uri=http%3A%2F%2Fdevel%2Fxxxxx・・・ とかになってて、なんでdevelになるのかなーってすごくハマりました。。。RAILS_ENV=develで動かしてるからそこからdevelがきてるのかと思ったら、結論から言うとリバースプロキシを設定しているからだったorz...
upstream devel { ってやつ。

探しても探しても localhost:3000でログイン出来ない記事しかあがってこなくて、リバースプロキシって単語も全然出てこなくて(というかそこが原因ってわかってなかったからだけど)まるまる2日かかってしまった。

以下、備忘録的に最終の設定ファイルを載せておくー。
あー疲れた。。。


/etc/nginx/conf.d/house.devel.conf
upstream devel {
server 127.0.0.1:8080 fail_timeout=4;
}

server {
listen 80;
root /var/www/house/devel/current/public;
server_name _;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://devel;
}
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;

add_header ETag "";
break;
}
}

~/database.devel.yml
devel:
adapter: postgresql
encoding: utf-8
database: house_development
pool: 5
username: appman
password: xxxxxx

confing/environments/devel.rb
config.omniauth :facebook, '1234567', 'abcdefghijklmnopqrstuvwxyz', :scope => 'email'
OmniAuth.config.full_host = lambda do |env|
# http or https
scheme = env['rack.url_scheme']
local_host = env['HTTP_HOST']
forwarded_host = env['HTTP_X_FORWARDED_HOST']
forwarded_host.blank? ? "#{scheme}://#{local_host}" : "#{scheme}://#{forwarded_host}"
end