Get IP Address of client without web scripts (like php)

Figured I’d do a quick post about this, I had the need to show my IP address (like but internal).  I didn’t really feel like adding php to my existing nginx server, so here’s what I did.

First) I create a new virtual-host with the internal server-name (or ip) of my nginx server, new document root of “ip” and a quick index.html.  The contents of the index.html are really simple


okay, but how does that give me my ip address?  Well I want nginx todo this for me, so here’s my nginx config.

server {
listen 80;
listen [::]:80;
root /var/www/html/ip;
location / {

sub_filter ‘nginx_ip_address’ ‘$remote_addr’;
sub_filter_once off;

Really Simple find/replace type method to switch out the text with the IP address.

That’s it.

Say Something Nice