Hi All,
I am using a Mojolicious service behind an nginx reverse proxy. Within my
service I want to record the originating IP of the request, however
$controller->tx->remote_address returns the address of the proxy and
$controller->tx->original_remote_address returns 127.0.0.1.
When I dump out the values from the mojo controller this is what I get (IP
addresses masked for this post)
$controller->req->headers->header('X-Forwarded-For') = "[originating IP],
[proxy IP]"
$controller->tx->remote_address = "[proxy IP]"
$controller->tx->original_remote_address = "127.0.0.1"
I have read other threads on this issue which suggest that the fix for this
issue is to have proxy => 1 in the hypnotoad config. I checked and found
that I already had this in my hypnotoad config before I encountered this
problem, I additionally tried setting $ENV{MOJO_REVERSE_PROXY} = 1 which
also had no effect.
It was also suggested that the nginx config should contain the following
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Remote-Port $remote_port;
Below is the relevant section cut and pasted from my actual nginx config,
and it seems to me that I do at least have the two most relevant lines for
the X-Real-IP and X-Forwarded-For headers.
real_ip_header X-Forwarded-For;
real_ip_recursive on;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
As it is right now, I have had to implement a solution where I manually
parse the content of $controller->req->headers->header('X-Forwarded-For').
This just doesn't seem right to me. Where am I going wrong?
Thanks for your time,
Sam
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.