0

我將站點從已停用的OpenShift v2轉移到AWS上的LightSail。我已經在LightSail上運行該應用程序,並在外部轉發,其格式爲localhost:3333。我能夠使用site-url.com反向代理髮送127.0.0.1作爲URL,而不是外部site-url.com到oauth回調

拉起該網站但試圖登錄到應用程序(使用Passport Facebook)。回調URL是越來越設置爲127.0.0.1,而不是白名單(臉譜DEV)www.site-url.com

https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A3333%2Fauth%2Fwww.site-url.com%2Fauth%2Ffacebook%2Fcallback&scope=email&client_id=XXX

相關的登錄代碼:

const appUrl = "www.site-url.com"; 
const callbackURL = appUrl + "/auth/facebook/callback"; 
passport.use(new FacebookStrategy({ 
       clientID: clientID, 
       clientSecret: clientSecret, 
       callbackURL: callbackURL, 
       profileFields: ['id', 'displayName', 'email'] 
     }, 

... 

app.get('/auth/facebook', 
     passport.authenticate('facebook', { scope: ['email'] })); 

app.get('/auth/facebook/callback', 
     passport.authenticate('facebook',{ 
      successRedirect: appUrl + '/profile', 
      failureRedirect: appUrl + '/?login-failed'} 
     )); 

我加appUrl,試圖通過服務器來解決它碼。不過,我有一種感覺,Apache會更適合解決這個問題。

我設置了代理服務器,以下these instructions,並試圖127.x/site-url.com

ProxyPass/http://127.0.0.1:3333/ 
# ProxyPass/http://www.site-url.com/ 
ProxyPassReverse/http://127.0.0.1:3333/ 
# ProxyPassReverse/http://www.site-url.com/ 

任何人的所有變化有什麼想法?

+1

嘗試在'ProxyPass'之前添加'ProxyPreserveHost On'' –

+0

謝謝@DusanBajic,這正是需要的:) –

回答

1

打開PreserveHost解決了這個問題,Facebook的現在接收到正確的回調URL

PreserveHost:

ProxyPreserveHost On 
ProxyPass/http://127.0.0.1:3333/ 
ProxyPassReverse/http://127.0.0.1:3333/ 

Apache的配置:

vim /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf

附加: Include "/home/bitnami/conf/httpd-app.conf

Start up the app using screen避免在SSH進程被終止時關閉。也許試試nodemon for resiliency

謝謝,@DusanBajic!