$c->req->base するとhttp://127.0.0.1/が返ってくる


どうも、着々とデブになりつつ有るたかとしです。

そろそろランニングしないとマジでまずい。豚になる。

本題。

apache

ServerName www.example.com
ProxyPass /peropero/m http://127.0.0.1:3000/m
ProxyPassReverse /peropero/m http://127.0.0.1:3000/m

とやっていて、

さらにCatalystのRoot.pmで

my $base = $c->req->base;

とやると、$baseに「http://127.0.0.1/」が返ってくる。。
あれ、「http://www.example.com/」じゃないの?
どうしたらいいの?

と思ってマニュアルをチェック。

% perldoc Catalyst
/PROXY
PROXY SUPPORT
Many production servers operate using the common double-server
approach, with a lightweight frontend web server passing requests to a
larger backend server. An application running on the backend server
must deal with two problems: the remote user always appears to be
127.0.0.1 and the server's hostname will appear to be "localhost"
regardless of the virtual host that the user connected through.

Catalyst will automatically detect this situation when you are running
the frontend and backend servers on the same machine. The following
changes are made to the request.

$c->req->address is set to the user's real IP address, as read from
the HTTP X-Forwarded-For header.

The host value for $c->req->base and $c->req->uri is set to the real
host, as read from the HTTP X-Forwarded-Host header.

Additionally, you may be running your backend application on an
insecure connection (port 80) while your frontend proxy is running
under SSL. If there is a discrepancy in the ports, use the HTTP header
"X-Forwarded-Port" to tell Catalyst what port the frontend listens on.
This will allow all URIs to be created properly.

In the case of passing in:

X-Forwarded-Port: 443

All calls to "uri_for" will result in an https link, as is expected.

Obviously, your web server must support these headers for this to work.

In a more complex server farm environment where you may have your
frontend proxy server(s) on different machines, you will need to set a
configuration option to tell Catalyst to read the proxied data from the
headers.

MyApp->config(using_frontend_proxy => 1);

If you do not wish to use the proxy support at all, you may set:

MyApp->config(ignore_frontend_proxy => 0);

あれ、The host value for $c->req->base and $c->req->uri is set to the real host, as read from the HTTP X-Forwarded-Host header.って書いてんじゃん…?

いみふ。



追記:
結局、c->req->baseを上書きして対応した。
謎は深まるばかり…
いみふすぎてウンコもれるかと思った