Nginx代理与Google OAuth 2.0 [英] Nginx proxy with Google OAuth 2.0

查看:101
本文介绍了Nginx代理与Google OAuth 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ubuntu 14.04服务器,我有一个在此服务器上的localhost:3000运行的流星应用程序.我的服务器的公共FQDN为sub.example.com.流星应用程序使用Google OAuth 2.0,我在Google API控制台中配置了以下内容:

I have an Ubuntu 14.04 server and I have a meteor application that runs at localhost:3000 on this server. The public FQDN of my server is sub.example.com. The meteor application uses Google OAuth 2.0, I have the following configured in the Google API Console:

URI REDIRECTION  
http://sub.example.com/_oauth/google
http://sub.example.com/_oauth/google?close
 ORIGINES JAVASCRIPT 
http://sub.example.com

我的Nginx配置文件如下:

My Nginx config file looks like this:

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时,会弹出一个弹出窗口,提示:

The proxy works and I can access my meteor application when I go to sub.example.com. But when in this application I try to use Google OAuth 2.0, a pop up opens as it should and I get :

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/_oauth/google?close did not match a registered redirect URI.

我玩了nginx配置文件中的头文件,没有运气.

I have played with the header in the nginx config file with no luck.

我显然丢失了一些东西.

I'm obviously missing something.

推荐答案

您应该重写后端发送给Nginx的Location标头,如

You should rewrite the Location headers that your backend sends to Nginx described in http://wiki.nginx.org/HttpProxyModule#proxy_redirect, so:

proxy_redirect http://localhost:3000/_oauth/google http://sub.example.com/_oauth/google;

另一个适用于弹出式登录的选项是在启动时为Meteor设置ROOT_URL环境变量,如下所示:

the other option, that would work for popup-style login as well is to set the ROOT_URL environment variable for Meteor at startup as follows:

ROOT_URL="http://sub.example.com" PORT=3000 node main.js

这篇关于Nginx代理与Google OAuth 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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