反向代理发送 127.0.0.1 作为 URL,而不是外部站点-url.com 到 oauth 回调

Reverse Proxy Sending 127.0.0.1 as URL, instead of external site-url.com to oauth callback

我正在将站点从已停用的 OpenShift v2 转移到 AWS 上的 LightSail。我在 localhost:3333 上的 LightSail 上启动了应用程序并 运行,已从外部转发。我可以使用 site-url.com

拉起网站

但是,当尝试登录应用程序时(使用 Passport Facebook)。回调 url 被设置为 127.0.0.1,而不是白名单(facebook 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/

有人有什么想法吗?

打开 PreserveHost 解决了问题,Facebook 现在收到正确的回调 url

保留主机:

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 to avoid shutdown when SSH process is killed. Maybe try nodemon for resiliency

谢谢@DusanBajic!