Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In nginx's configuration, could "if (!-f $request_filename) {" cause a performance hit on virtual machines?

If nginx is configured as a reverse proxy, could the following bit of configuration (counter-intuitively) cause a performance hit?

    if (!-f $request_filename) {
        proxy_pass http://app_server;
        break;
    }

This checks if a file exists, then serves it and finishes the request. However, this may cause some I/O to happen. If that file system is slow, might it be possible that forwarding the request to the proxied service ends up being faster?

like image 240
mlbright Avatar asked Nov 02 '22 11:11

mlbright


1 Answers

Just like @mlbright said, if is bad, try to avoid it as much as you can, a good equivalent for the case you want to handle would be

location /whatever {
    try_files $uri @app_server;
}
location @app_server {
    proxy_pass http://app_server;
}
like image 179
Mohammad AbuShady Avatar answered Nov 09 '22 12:11

Mohammad AbuShady