DevOps Helper

How to do nested if in Nginx

Easy:

All you have to do is create variables which you can use in the next condition:


if ($http_client_device ~* "xyz") {
    set $mobile_device T;
}
if ($request_method = 'GET'){
    set $mobile_device "${mobile_device}G";
}
if ($request_method = 'POST'){
    set $mobile_device "${mobile_device}P";
}
if ($mobile_device = TG){
    rewrite ^ /index.html break;
}
if ($mobile_device = TP){
    return 200;
}