Nginx代理与谷歌OAuth 2.0
我有一个Ubuntu 14.04服务器,我有一个流星应用程序在此服务器上运行localhost:3000
。我的服务器的公共FQDN是sub.example.com
。流星应用程序使用谷歌的OAuth 2.0,我有以下的谷歌API控制台配置:Nginx代理与谷歌OAuth 2.0
URI REDIRECTION
http://sub.example.com/_oauth/google
http://sub.example.com/_oauth/google?close
ORIGINES JAVASCRIPT
http://sub.example.com
我的Nginx的配置文件看起来是这样的:
server {
listen 80 default_server;
server_name sub.example.com www.sub.example.com;
location/{
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3000;
}
}
代理的作品,我可以访问我的流星申请当我去sub.example.com
。但是,当这个应用程序,我尝试使用谷歌的OAuth 2.0,弹出打开,因为它应该和我得到:
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/_oauth/google?close did not match a registered redirect URI.
我打,在没有运气nginx的配置文件中的标题。
我明显错过了一些东西。
你应该重写Location
头,你的后台发送到Nginx的在http://wiki.nginx.org/HttpProxyModule#proxy_redirect描述,所以:
proxy_redirect http://localhost:3000/_oauth/google http://sub.example.com/_oauth/google;
的另一种选择,这将对于弹出式登录工作,以及是设置ROOT_URL
环境变量流星在启动时如下:
ROOT_URL="http://sub.example.com" PORT=3000 node main.js
'export ROOT_URL =“http://sub.example.com”'对我来说很合适,我甚至明白为什么。只是添加proxy_redirect没有。谢谢Hans Z .. – mthpvg 2015-02-23 22:22:01
是的,proxy_redirect可以用于非弹出式/全浏览器重定向环境 – 2015-02-23 22:25:00
很好的答案!为我节省了一两个小时!有关流星使用的全面环境变量,请参阅:http://www.meteorpedia.com/read/Environment_Variables – pkk 2015-10-20 16:45:11
您正在发送来自http:// localhost:3000/_oauth/google?的请求,并将其放在重定向uri中。在云端控制台上。 – DaImTo 2015-02-23 13:31:18
据我了解,这是行不通的,因为用户浏览器无法访问服务器的本地主机。但是,如果流星应用程序在我的笔记本电脑上,我可以做到这一点,它的工作。谢谢。 ' – mthpvg 2015-02-23 22:19:32