How to configure nginx better to reduce redundant system calls when APIs are called?
It looks like you are dealing with try_files
performance issue. You can get rid of unnecessary stat
system calls by eliminating try_files
from your configuration.
The try_files
directive provides a nice and simple boilerplate for creating SEO-friendly website.
However, the downside of this simplicity comes with an added cost of unnecessary stat
system calls.
Since you know that, for e.g. all /api/
URLs must be routed through your PHP, there is no need to check any files for existence there and you can route through your Laravel bootstrap file unconditionally, e.g.:
location /api/ {
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/example.com.sock;
}
Moreover, in general, you want to have NGINX cache information about file/directories existence. This can be achieved through open_file_cache.