テストサーバに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/" と変更してしまう
のです。
解決策は 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にリダイレクトさせた場合で
意図しない動きをした場合は見てみるといいとおもいます。