OmniAuth uses the wrong callback port in proxy callback configuration

I have a Rails application running on a port 3101, and I made it available on the Internet through the installation of a reverse Apache proxy (for example, the Phusion suggested by this blog post .

I am using Devise + OmniAuth for Facebook authentication.

But when I try to authenticate via Facebook, I am redirected to the URL: http://mydomain.com:3101/my_callback_path

I run the rails application using passenger start -a 127.0.0.1 -p 3101 -d, and my Apache installation:

<VirtualHost *:80>
    ServerName mydomain.com

    PassengerEnabled off
    ProxyPass / http://127.0.0.1:3101/
    ProxyPassReverse / http://127.0.0.1:3101

    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
      Order deny,allow
      Allow from all
    </Proxy>
</VirtualHost>

I found several answers like this and, but they are all designed to install Nginx.

OmniAuth.config.full_host = 'http://my domain.com', , apache (, ).

.

+5
2

OmniAuth , full_host, , URI - oa-core-0.2.6/lib/omniauth/strategy.rb

( ) Proc, nil ( - ). URI , .

, , Apache (, , ruby), , :

OmniAuth.config.full_host = lambda do |env|
    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
+12

.

**proxy_set_header        Host            <proxy-domain-name>;**



  location / {
  proxy_pass  http://127.0.0.1:3000;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header        Host            <domain name>;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
 }

facebook, URL-, , nginx conf. , URL- "redirect_uri" GET , , .

+1

All Articles