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.