- Edited
Can anyone improve this code as an alternative for the evil IF ?
location ~ \.php$ {
try_files $uri $uri/ =404;
set $mmode 0;
set_by_lua $notused '
s = 0;
local source_fname = ngx.var.document_root .. "/maintenance_mode.html";
local file = io.open(source_fname);
if file then ngx.var.mmode=1; file:close(); end;
s = string.find(ngx.var.remote_addr, "^10.10.");
if s then ngx.var.mmode=0; end;
';
if ($mmode) { return 503; }
index index.html index.htm index.php;
[...]
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
[...]
}
It works very well but having doubts about the string.find value, I think I need to escape the dots...
location ~ \.php$ {
try_files $uri $uri/ =404;
set $mmode 0;
set_by_lua $notused '
s = 0;
local source_fname = ngx.var.document_root .. "/maintenance_mode.html";
local file = io.open(source_fname);
if file then ngx.var.mmode=1; file:close(); end;
s = string.find(ngx.var.remote_addr, "^10.10.");
if s then ngx.var.mmode=0; end;
';
if ($mmode) { return 503; }
index index.html index.htm index.php;
[...]
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
[...]
}
It works very well but having doubts about the string.find value, I think I need to escape the dots...