Welcome! Log In Create A New Profile

Advanced

Escaping/quoting variable names in config files

Posted by jschuur 
Escaping/quoting variable names in config files
July 29, 2010 10:16PM
In an attempt to centralize my common configuration data for the server block as much as possible, my document root follows a naming convention based on each site's server_name. This means I can use directives like 'root /www/$server_name/htdocs;' just fine in shared .conf file that I include from multiple places in the main sites.conf file.

This works great when paths are separated with slashes, however, I don't know what to do when the filename I want to get at is supposed to include the server_name as a substring. If I use $server_name-access.log, e.g. in an effort to get domain.com-access.log (assuming server_name is domain.com), it won't work, presumably because it's looking for a variable called $server_name-access.

Is there a way to properly quote the variable name, so it's clear where I want the parsing to end in nginx? I've tried $(server_name)-access.log or ${server_name}-access.log, but that didn't work.

Basically, what I had in mind was:

[b]sites.conf[/b]
server {
server_name domain1.com;
include sites-shared.conf;
}

server {
server_name domain2.com;
include sites-shared.conf;
}

[b]sites-shared.conf[/b]
listen 80;
root /www/$server_name/htdocs;

access_log /var/log/nginx/$server_name$log_suffix main;
error_log /var/log/nginx/$server_name-error.log;
...

Alternatively, can I set a custom variable and later refer to it? Then I could set $accesslog_suffix to '-access.log' and use $server_name$accesslog_suffix e.g.. According to a [url=http://forum.nginx.org/read.php?2,2030,2038]post from last year[/url], this won't work though.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 191
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready