Omniauth Nginx Unicorncallback到错误的主机URL

我已经部署了Rails应用程序到VPS服务器,我使用的Nginx /独angular兽组合,一切工作正常,除了由于某种原因超出我的理解,Omniauthcallbackredirect错误,

即。

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中定义的上游名称callback?

 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; } } 

你可以帮我吗? 我需要知道如何克服这个错误的redirect。

提前致谢!

Nginx默认不通过主机头,你必须告诉它:

  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; } 

否则,发送请求的主机就会丢失。