DocumenRoot for Nginx (declare a variable)

Continuing the discussion from Default nginx document root for new virtual servers:

OS type and version: 20.04

Unfortunately the link at this thread is dead (404).
So I like to know if it’s possible to declare something in the nginx-default skeleton, which is used in every new NGINX-Conf in sites-available.

What I try to do?
I want to put the document-root into an variable via:

set $docRoot/my_root;
root /$docRoot;

But the path should be not hard-coded, but the one, NGINX would anyway set as default server path.
It’s needed because I want to create location-directives in seperate conf-files, which should be included into the user-conf:
include /etc/nginx/conf.d/staticRootPath.conf
An in there in this file, I want to use:

# static files for nginx (not for apache)
location ~* ^.+\.(jpg|jpeg|js|png|css)$ {
  root $docRoot;

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.