silent11 has asked for the wisdom of the Perl Monks concerning the following question:

I have to admit up front, this is probably more of an Nginx question, but here goes: I have a Mojolicious::Lite app that does some simple visitor logging. I'm capturing the IP, requested path, and timestamp of the visit to a database. This all worked fine under morbo, Mojo's built-in development web server.
my $ip = $self->tx->remote_address;
Yesterday I launched the app under hypnotoad, behind nginx and now I no longer get accurate user IPs. All requests now appear as 127.0.0.1. This would make sense as the requests are coming through nginx.

some of what I read online suggests that I can get to the real IP like this:
$self->req->headers->header('X-Real-IP')
with the associated addition to my Nginx config:
proxy_set_header X-Real-IP $remote_addr;
However I'm still getting 127.0.0.1 after modifying my app to pull X-Real-IP, and restarting the server :(

Here is my Nginx config:
upstream myapp { server 127.0.0.1:8080; } server { listen 80; server_name localhost; #include /etc/nginx/proxy_params; location / { proxy_pass http://myapp; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; #proxy_set_header X-Remote-Port $remote_port; } }

Replies are listed 'Best First'.
Re: Getting visitor IP from Mojolicious::Lite behind Nginx
by beech (Parson) on Oct 18, 2016 at 23:54 UTC

    However I'm still getting 127.0.0.1 after modifying my app to pull X-Real-IP, and restarting the server :(

    :) Try Mojolicious::Plugin::RemoteAddr, it retrieves x-real-ip or x-forwarded-for or tx->remote_address