Nginx代理与Google OAuth 2.0

mth*_*pvg 6 proxy nginx meteor google-oauth

我有一个Ubuntu 14.04服务器,并且有一个localhost:3000在此服务器上运行的流星应用程序。我的服务器的公共FQDN是sub.example.com。流星应用程序使用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
Run Code Online (Sandbox Code Playgroud)

我的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;
    }
}
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

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

I'm obviously missing something.

Han*_* Z. 5

您应该重写Location后端发送给Nginx 的标头,如http://wiki.nginx.org/HttpProxyModule#proxy_redirect中所述,因此:

proxy_redirect http://localhost:3000/_oauth/google http://sub.example.com/_oauth/google;
Run Code Online (Sandbox Code Playgroud)

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

ROOT_URL="http://sub.example.com" PORT=3000 node main.js
Run Code Online (Sandbox Code Playgroud)