3 ms·
A while back I needed a no-cruft way to get my IP reliably, so put this in my nginx config, to allow "curl example.com/ip": http { # ... perl_modules
by tedchs 13y ago
A while back I needed a no-cruft way to get my IP reliably, so put this in my nginx config, to allow "curl example.com/ip":
http {
# ...
perl_modules /etc/nginx/perl;
perl_require myip.pm;
# ...
server {
# ...
location = /ip {
perl myip::handler;
}
# ...
}
}
then in /etc/nginx/perl/myip.pm :
---
package myip;
use nginx;
sub handler {
my $r = shift;
$r->send_http_header("text/plain");
return OK if $r->header_only;
$r->print($r->remote_addr() . "\n");
return OK;
}
1;
---