2

all-Flask-OpenID拡張機能を使用するサイトをデプロイしようとすると問題が発生します。ローカルホストでは、フルログインを移動するのに問題はありません->ログインサイクル後-しかし、Flaskアプリの前でNginxプロキシを実行している(Gunicornで実行している)本番サーバーでは、openidでエラーが発生します。接続しているプロバイダーからの応答のrealmおよびopenid.return_toパラメーター。

基本的に、realmとreturn_toは、プロキシサーバーではなくダウンストリームのFlaskアプリを指しています。たとえばhttp://www.foo.com/login/、Flask-OpenID機構の意図された「次の」URLは、代わりにプロバイダーをターゲットhttp://127.0.0.1:8000/login/?next=/login/にします。これは、Flaskアプリが実行されているローカルホストとポートです。

この動作を制御し、Flask-OpenIDをプロキシサーバー経由で正しくリダイレ​​クトする方法はありますか?

4

1 に答える 1

1

It sounds like your proxy server isnt passing on the HOST header, using nginx you can use proxy_set_header Host $host; in your location directive.

You may also want to look at setting the X-Forwarded-For and X-Forwarded-Proto headers so you can read the actual client IP and protocol correctly. Werkzeug provides a fixer to help with this, and there's an example detailed in the Flask docs, request.remote_addr should then be what you expect.

Here's a more complete nginx location directive:

location / {
    proxy_pass  http://localhost:8000/;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
于 2013-01-29T15:19:01.290 に答える