Hi I am looking to set up a simple nginx config, I read you can set variables using set $variable content;
but so far I've had no luck...
Below is what I have come up with so far/what I am trying to achieve:
server {
##################################################
# Set variables
set $port 80; # e.g. 80 or 443;
set $domain domain.com *.domain.com; # e.g. www.domain.com or just domain.com
set $subdomain false; # e.g. subdomain in subdomain.domain.com or false
set type live; # live, dev or stage
##################################################
# Include /web/sites configuration template
include /etc/nginx/site-config-template;
}
Here are the contents of /etc/nginx/site-config-template:
##################################################
# If $subdomain is not false at slash
if ( $subdomain ) {
set $subdomain "{$subdomain}/";
}
##################################################
# Define server main variables
listen $port;
server_name $domain;
root /web/sites/$domain/$subdomain$type/public_html/current/;
index index.php index.html;
##################################################
# Logs
access_log /web/sites/$domain/$subdomain$type/logs/access.log;
error_log /web/sites/$domain/$subdomain$type/logs/error.log;
##################################################
# push all to index.php
location / {
try_files $uri $uri/ /index.php$args;
}
##################################################
# pass php files to fastcgi
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SITE_TYPE $type;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
Am I not able to set variables in this manner in config files or am I just doing something horribly wrong?
set
, I would prefer doing configuration template in CM (configuration management) tools like puppet, ansible, salt, chef, cfengine and friends.listen
norserver_name
accepts variables. Describe what you want to achiveserver_name
accept only one variable ($hostname
) for historical reasons. But it just accepts any string. Soserver_name $var
actually expects headerHost: $var
.