我有一个 Ubuntu 14.04 服务器,并且有一个运行在以下位置的流星应用程序localhost:3000
在此服务器上。我的服务器的公共 FQDN 是sub.example.com
。 Meteor 应用程序使用 Google OAuth 2.0,我在 Google API 控制台中进行了以下配置:
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
。但是,当我在此应用程序中尝试使用 Google 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 http://wiki.nginx.org/HttpProxyModule#proxy_redirect, so:
proxy_redirect http://localhost:3000/_oauth/google http://sub.example.com/_oauth/google;
另一个选项也适用于弹出式登录,即设置ROOT_URL
Meteor启动时的环境变量如下:
ROOT_URL="http://sub.example.com" PORT=3000 node main.js
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)