Omniauth Nginx Unicorn回调到错误的主机URL [英] Omniauth Nginx Unicorn callback to wrong host URL

查看:109
本文介绍了Omniauth Nginx Unicorn回调到错误的主机URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Rails应用程序部署到VPS服务器上,并且使用的是Nginx/Unicorn组合,一切正常,除了出于我无法理解的原因,Omniauth回调重定向错误,

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,

即.

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

它应该是:

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

怎么了?为什么使用nginx中定义的上游名称进行回调?

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.

提前谢谢!

推荐答案

Nginx默认不传递主机头,您必须告诉它:

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.

这篇关于Omniauth Nginx Unicorn回调到错误的主机URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆