Poundの設定でリダイレクトが効かない場合

Pound

Pound + Apache の環境で、特定のページに来た際に違うサブドメイン(同一の環境に存在する)へリダイレクトを行った場合に上手くいかなかったので、その際に変更した内容をメモしておきます。

まず、どう言う環境で発生したものなのかを下記にまとめておきます。

[shell]
Pound
|
Apache (web)
├  http://www1.example.co.jp/ (virtualhost)
└  http://www2.example.co.jp/ (virtualhost)
[/shell]

Pound側の設定(/etc/pound.cfg)は下記の通りです。

[shell]
….
ListenHTTP
Address xxx.xxx.xxx.xxx
Port 80
xHTTP 0

Service
HeadRequire “Host: .*.example.co.jp.*”
BackEnd
….
End
End
End
….
[/shell]

Apache(httpd.conf)については、下記通りです。

[shell]

DocumentRoot ….
ServerName www1.example.co.jp
….

DocumentRoot ….
ServerName www2.example.co.jp
….

[/shell]

次に www1.example.co.jp 側に、下記のようなPHP(sample.php)を設置します。

[php]

  これらの設定をしている環境で、下記のような事象が発生していました。

www1.example.co.jp/sample.php へアクセスした際に、www2.example.co.jp にリダイレクトされるはずですが、www1.example.co.jp へリダイレクトされてしまいます。

他のドメインへのリダイレクトについては問題なく動きますので、この環境での問題と言うことが判明しました。 Pound側でログを確認したところ、リダイレクト直後に www1.example.co.jp となっているため location で書き換えた内容がどこかで消えてる or 書き換わってるのではと思い確認してみたところ、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.

“2” だと BackEnd からのリダイレクトがそのまま有効になる様なので、RewriteLocation を /etc/pound.cfg へ設定をします。

[shell]
….
ListenHTTP
Address xxx.xxx.xxx.xxx
Port 80
xHTTP 0

RewriteLocation 2

Service
HeadRequire “Host: .*.example.co.jp.*”
BackEnd
….
End
End
End
….
[/shell]

  次に Pound の再起動です。

[shell]
sudo /etc/init.d/pound restart
[/shell]

  この状態で、再度 www1.example.co.jp/sample.php へアクセスしたところ、問題なく www2.example.co.jp へとリダイレクトされました。

デフォルトでは “1” となっているようなので、同じような事象で困っている方がいましたら一度、”2″ へ設定を変更して見ることをお勧めします。

コメント

タイトルとURLをコピーしました