If block issues

In some situations, if not most, you should avoid using if blocks. There are two main issues that occur if you do so, regardless of the Nginx build you are using.

Inefficient statements

There are some cases where if is used inappropriately, in a way that risks saturating your storage device with useless checks:

location / {
    # Redirect to index.php if the requested file is not found
    if (!-e $request_filename) {
       rewrite ^ index.php last;
    }
}

With such a configuration as the preceding one, every single request received by Nginx will trigger a complete verification of the directory tree for the requested filename, thus requiring multiple storage disk access system calls. If you test /usr/local/nginx/html/hello.html, Nginx will check

Get Nginx HTTP Server - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.