Omniauth Nginx Unicorn callback to wrong host URL

久未见 提交于 2019-12-13 01:27:14

问题


I've deployed a Rails app to a VPS server, and I'm using the Nginx/Unicorn combo, everything works fine, except that for some reason beyond my understanding, the Omniauth callbacks redirect wrong,

ie.

http://unicorn/users/auth/linkedin/callback?oauth_token=95218ed3-b426-45ab-b022-693d2a2447cb&oauth_verifier=25955

it should instead be:

http://my-real-domain.com/users/auth/linkedin/callback?oauth_token=95218ed3-b426-45ab-b022-693d2a2447cb&oauth_verifier=25955

What's wrong? why is the callback using the name of the upstream defined in nginx?

upstream unicorn {
  server unix:/tmp/unicorn.todo.sock fail_timeout=0;
}

server {
  listen 80;
  listen [::]:80 ipv6only=on default_server;

  root /home/deploy/work/project/current/public;
  index index.html index.htm;

  server_name my-real-domain.com;

  try_files $uri/index.html $uri @unicorn;

  location @unicorn {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Client-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;

  location ~ ^/assets/ {
    expires 1y;
    add_header Cache-Control public;

    add_header ETag "";
    break;
  }
}

Could you please help me? I need to know how to overcome this wrong redirection.

Thanks in advance!


回答1:


Nginx doesn't pass the host header by default, you have to tell it to:

 location @unicorn {
    proxy_set_header Host $http_host; 
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Client-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://unicorn;
  }

Otherwise which host the request was sent to gets lost.



来源:https://stackoverflow.com/questions/16159998/omniauth-nginx-unicorn-callback-to-wrong-host-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!