Welcome! Log In Create A New Profile

Advanced

using variables in nginx.conf with 'set'

Arthur Blake
October 22, 2010 08:32AM
It seems like the set command was designed for use in a narrow set of
circumstances. But I think it would be a lot more useful if the variables
it defines could be used globally with any directive.

I am trying to use the 'set' command in order to define my own variables
that define things that may vary by server in a main nginx.conf file so that
a generic reusable include file can later use those variables. It seems
that the variables only work in certain places with certain directives.

Is there a reason I can't use variables set this way more widely? I would
like to be able to use variables like this anywhere in the config files.

In the example below, I define two variables with the 'set' command,
$rootfolder and $backend.

The $rootfolder variable doesn't work with the include directive and the
$backend doesn't work with the proxy_pass directive.
But the $rootfolder does work with the $alias directive.

#main nginx.conf
server
{
listen 80;
server_name www.justatest.xxx
set $rootfolder /Development
set $backend http://127.0.0.1:8080
# This doesn't work!
# include $rootfolder/mytest/vhost.conf;
# have to use this instead
include /Development/mytest/vhost.conf;
}


#vhost.conf include

location /
{
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Rewrite-URL $request_uri;
# this doesn't work!
# proxy_pass $backend;
# have to use this instead
proxy_pass http://127.0.0.1:8080;
}

location /resources/
{
# this DOES work
alias $websites/www/resources/;
}


--Thanks
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

using variables in nginx.conf with 'set'

Arthur Blake October 22, 2010 08:32AM

Re: using variables in nginx.conf with 'set'

Adrian Janeczek October 22, 2010 09:58AM

Re: using variables in nginx.conf with 'set'

Maxim Dounin October 22, 2010 11:44AM

Re: using variables in nginx.conf with 'set'

Arthur Blake October 22, 2010 03:20PM

Re: using variables in nginx.conf with 'set'

jazzhuang November 03, 2014 02:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 301
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