'Get boolean return from another program for if statement Nginx
To Block access to wp-admin for all others countries, just accept my country, also blocked proxy. I have a app Perl, who return a boolean true when for example is other_country_or_proxy()
To avoid compile nginx with geoip I want to just used perl in nginx, so sudo apt install nginx-extras (ngx_http_perl_module)
nginx.conf:
http {
perl_modules /mnt/f/lib;
perl_require App.pm;
example.com.conf:
location ~ ^/(wp-admin|wp-login.php) {
perl App::handler;
}
location / {
autoindex on;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/example_example.com_php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /public_html/$fastcgi_script_name;
include fastcgi_params;
}
App::handler:
use nginx;
use Geo::IP2Proxy;
sub handler {
my $r = shift;
my $obj = Geo::IP2Proxy->open("/mnt/f/App/IP2PROXY.BIN");
my $isproxy = $obj->isProxy("1.1.1.1");
$r->send_http_header("text/html");
return OK if $r->header_only;
if ( $isproxy ) {
$r->print("bad!\n<br/>");
}
else{
$r->print("good!\n<br/>");
}
return OK;
}
The above code work, I get print the result string in example.com/wp-login.php
but I want something like this:
location ~ ^/(wp-admin|wp-login.php) {
if( perl App::handler ){ **(I need this)**
return 503;
}
if not continue normal request php **(I need this)**
}
sub handler {
my $r = shift;
my $obj = Geo::IP2Proxy->open("/mnt/f/App/IP2PROXY.BIN");
my $isproxy = $obj->isProxy("1.1.1.1");
if ( $isproxy ) {
return "1";
}
return "0";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
