Figured I’d do a quick post about this, I had the need to show my IP address (like https://www.icanhazip.com/ 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
nginx_ip_address
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;
server_name 192.168.11.6;
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.