2016-07-20 93 views
0

我想實現一個簡單的谷歌的OAuth使用本指南以下passport.js我Express.js的應用程序(只需更換facebookgooglehttps://github.com/passport/express-4.x-facebook-example/blob/master/server.jsPassport.js表示谷歌的OAuth 502錯誤的網關上的nginx

當我在本地嘗試,事情似乎運作良好。當我將其部署到我的Ubuntu生產服務器時,在從Google重定向回調到/login/google/return端點期間出現502 Bad Gateway錯誤。

app.get('/login/google/return', 
    passport.authenticate('google', { failureRedirect: '/login' }), 
    function(req, res) { 
    res.redirect('/'); 
    }); 

如果我註釋掉行passport.authenticate('google', {..}),那麼錯誤就會消失。在檢查Nginx的錯誤日誌,我看到這個錯誤

upstream sent too big header while reading response header from upstream 

下面是nginx的服務器配置塊:

location /auth/ { 
    proxy_pass http://0.0.0.0:3000/; 
} 

這意味着我需要登錄轉到https://example.com/auth/login/google,被重定向到https://example.com/auth/login/google/return?code=4/adasfdafdsfd#谷歌,然後發生502錯誤。

我已經嘗試在我的OS X開發機器上設置一個類似的nginx環境,但問題不會發生在那裏。

我也試圖添加以下nginx的塊配置,但似乎並沒有幫助任何

proxy_buffers 8 16k; 

我在我束手無策爲如何調試/解決這個問題。任何人的建議將不勝感激。這裏是我的項目到目前爲止的鏈接https://github.com/tnguyen14/auth/blob/master/index.js

+0

爲了確保我理解正確,如果您訪問https://example.com/auth/login/google/,您將獲得您的登錄頁面,但是如果您轉到https://example.com/auth/登錄/谷歌/返回你得到502.你真的試着去https://example.com/auth/login/google/return?只需在地址欄中輸入該地址,然後按回車鍵,你會得到502嗎? – Molda

+0

看看這個http://stackoverflow.com/q/23844761/3284355 – Molda

+0

@Molda如果我直接去'/ login/google/return',它可以正常工作,因爲它會重定向到Google的帳戶選擇器頁面。只有當Google使用502發生的代碼重定向到'/ login/google/return'時。 我不認爲你鏈接的答案是非常相關的,因爲我沒有使用fastcgi。 –

回答

0

所以我很接近。 proxy_buffers 8 16k;是不夠的。同時添加以下行來Nginx的固定它:

proxy_buffers 8 16k; 
proxy_buffer_size 32k; 

更新:原來,它爲什麼抱怨頭大小的原因是因爲我沒有serialize用戶配置文件充分,所以對象是太大cookie。由於我使用的是cookie-session,因此所有這些數據都塞進cookie中,使其變得太大。

削減將被序列化通過護照會話的事情解決了這個問題,沒有添加nginx配置。