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; } }

In reply to Getting visitor IP from Mojolicious::Lite behind Nginx by silent11

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.