Welcome! Log In Create A New Profile

Advanced

How to get the hostname by perl?

Posted by huangqi 
How to get the hostname by perl?
July 20, 2012 03:10PM
Hi everyone,

I need to get the hostname by perl. My perl file is as follow:

package testperl;
use nginx;
sub testperl {
$r = shift;
my $url = $r->uri;
$r->discard_request_body;
$r->send_http_header;
$r->print($url);
$r->rflush;
return OK;
}
1;
__END__

But it hadn't hostname. As follow:
$ curl http://localhost/wp-content/themes/twentyten/images/wordpress.png
/wp-content/themes/twentyten/images/wordpress.png

How to get the hostname 'localhost' by perl? Thanks.
Re: How to get the hostname by perl?
August 31, 2013 03:07AM
I know this is a year old thread but just to help someone in the future as it is not documented clearly:

There is a $r->variable(name) function

So just do this

$r->variable(host)

Basically any variable you'd use in your nginx conf/inc files is available to perl in that way.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 90
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready