I am trying to implement a simple Google OAuth for my Express.js app using passport.js following this guide (just replace facebook
with google
) https://github.com/passport/express-4.x-facebook-example/blob/master/server.js
When I try it locally, things seem to be working well. When I deploy it to my Ubuntu production server, I get a 502 Bad Gateway
error during the redirect callback from Google to the /login/google/return
endpoint.
app.get('/login/google/return',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
If I comment out the the line passport.authenticate('google', {..})
, then the error goes away. Upon inspecting nginx error log, I see this error
upstream sent too big header while reading response header from upstream
Here's the server configuration block for nginx:
location /auth/ {
proxy_pass http://0.0.0.0:3000/;
}
Which means that I would log in to google by going to https://example.com/auth/login/google
, being redirected to https://example.com/auth/login/google/return?code=4/adasfdafdsfd#
, and then the 502 error happens.
I have tried setting up a similar nginx environment on my OS X development machine, but the problem does not occur there.
I have also tried to add the following to the nginx block configuration, but that doesn't seem to help either
proxy_buffers 8 16k;
I am at my wit's end as to how to debug/ solve this problem. Anyone's suggestion would be greatly appreciated. Here's the link to my project so far https://github.com/tnguyen14/auth/blob/master/index.js