Nginx Map how to check value if empty

c0nw0nk nginx-forum at forum.nginx.org
Sun Mar 5 21:50:53 UTC 2017


Thank's for the info :)

But why is $remote_addr outputting a hyphen instead of the users IP...

I still expect to see the client's IP address.

B.R. via nginx Wrote:
-------------------------------------------------------
> That is because it is not: your eyes deceived you having a too quick
> look
> at the log line.
> 
> Your 'empty' variables are actually showing the value '-' in this log
> line.
> It probably does not help debugging to have static '-' mixed in the
> format
> of your log lines where you put them.
> ---
> *B. R.*
> 
> On Sun, Mar 5, 2017 at 10:00 PM, c0nw0nk <nginx-forum at forum.nginx.org>
> wrote:
> 
> > Francis Daly Wrote:
> > -------------------------------------------------------
> > > On Fri, Mar 03, 2017 at 10:47:26AM -0500, c0nw0nk wrote:
> > >
> > > Hi there,
> > >
> > > > map $http_cf_connecting_ip $client_ip_from_cf {
> > > > default $http_cf_connecting_ip;
> > > > }
> > > >
> > > > How can I make it so if the client did not send that $http_
> header
> > > it makes
> > > > $client_ip_from_cf variable value = $binary_remote_addr
> > > >
> > > > Not sure how to check in a map if that http header is present.
> > >
> > > If the http header is absent, the matching variable is empty. So
> it
> > > will
> > > have the value "".
> > >
> > > Use that as the first half of your "map" pair.
> > >
> > >       f
> > > --
> > > Francis Daly        francis at daoine.org
> > > _______________________________________________
> > > nginx mailing list
> > > nginx at nginx.org
> > > http://mailman.nginx.org/mailman/listinfo/nginx
> >
> >
> > Hey Francis,
> >
> >
> > HTTP BLOCK
> > log_format cf_custom 'CFIP:$http_cf_connecting_ip - $remote_addr -
> > $remote_user [$time_local]  '
> > '"$request" Status:$status $body_bytes_sent '
> > '"$http_referer" "$http_user_agent"'
> > '$http_cf_ray';
> > map $status $loggable {
> > ~^[23]  0;
> > default 1;
> > }
> > access_log logs/access.log cf_custom if=$loggable;
> >
> > map $remote_addr $client_ip_from_cf {
> > default $remote_addr;
> > }
> >
> >
> > Access.log output
> > CFIP:- - 10.108.22.40 - - [05/Mar/2017:21:27:50 +0100]  "GET
> >
> >
> > Any idea why the remote_addr is empty surely it should display to me
> the
> > clients IP address i am not proxying traffic or anything like that.
> I
> > expected to see an IP there instead it seems the value is empty.
> >
> > Posted at Nginx Forum: https://forum.nginx.org/read.p
> > hp?2,272744,272766#msg-272766
> >
> > _______________________________________________
> > nginx mailing list
> > nginx at nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
> >
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,272744,272768#msg-272768



More information about the nginx mailing list