0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pound経由でLocationヘッダーを返す場合の注意点

Posted at

テストサーバにPoundを入れていろんなサービスのテストをしているのですが
httpでアクセスした際、httpsにリダイレクトしたいのに、なぜかhttpになってしまう現象があり
具体的には

80portのアクセスはPoundが受け取る
PoundはApacheのVirtualHostの8080に転送する
ApacheはMod_rewriteを利用してURIを保持したままhttpsにRedirectする
Apacheからは”Location: https://hoge.jp/”というヘッダ付きで出力される
Poundがリクエストしてきた端末に返す

単なるリバースプロキシでの処理ですが
Poundがなぜか"Location: https://hoge.jp/" を "Location: http://hoge.jp/" と変更してしまう
のです。

スクリーンショット 2019-08-09 14.50.06.png

解決策は RewriteLocation 0 を仕込むことでした。

ListenHTTP
    Address 0.0.0.0
    Port    80
    Client  120
    xHTTP   1
    AddHeader "X-Forwarded-Port: 80"
    RewriteLocation 0

    Service
        HeadRequire "Host: hoge.jp"
        BackEnd
            Address 127.0.0.1
            Port    8002
            Priority 1
        End
    End
End

man poundでドキュメントを読むと・・

   RewriteLocation 0|1|2
          If 1 force Pound to change the Location: and Content-location: headers in responses. If they point to the back-end itself or to  the
          listener  (but  with  the wrong protocol) the response will be changed to show the virtual host in the request. Default: 1 (active).
          If the value is set to 2 only the back-end address is compared; this is useful for redirecting a request to an HTTPS listener on the
          same server as the HTTP listener.

どうもまちがってたりしてるのを修正してくれるような機能っぽいのですが・・
いろいろ試してみましたが、同一ホスト名の場合はSchemaは元と同じにしたがる傾向で
別なドメインにリダイレクトする際はそのままだったりします。

Pound + apacheやPHP(Header("Location: https://〜);)でhttp->httpsにリダイレクトさせた場合で
意図しない動きをした場合は見てみるといいとおもいます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?