I've been trying to find out a way to first capture environment variable HOSTNAME and then use a MySQL query to fetch and return back to the Nginx conf the document root for our vhosts. We use them for dynamic doc roots currently in Apache but are migrating to Nginx.
example nginx.conf (might look something like this):
server {
listen 80;
# grab Environment variable HOSTNAME
$hostname= ENV(HOSTNAME);
# execute mysql query
$doc_root = mysql(select docroot from table where host = '$hostname' );
# set document root
root /var/www/$doc_root;
..... I was exploring using Lua and https://github.com/openresty/lua-resty-mysql but have been unable to figure out how this could be done to capture HOSTNAME and mysql query as a variable and return the results back.