how to programatically set nginx configuration directives to nginx.conf?

Solution 1:

In many distributions, there is a include conf.d/*.conf line in nginx.conf http section.

So, the script can create a file in conf.d directory with .conf extension and the reload nginx configuration.