Nginx proxies with Google OAuth 2.0

I have a Ubuntu 14.04 server, and I have a meteor application that runs localhost:3000on this server. The fully qualified domain name of my server sub.example.com. The meteor application uses Google OAuth 2.0, I have the following configuration 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

My Nginx configuration 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;
    }
}

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 popup 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.

I played with the header in the nginx configuration file with no luck.

I am clearly missing something.

+4
1

Location, Nginx, http://wiki.nginx.org/HttpProxyModule#proxy_redirect, :

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
+4

All Articles