Set a variable in configuration file

A really stupid question: how do I set a variable in Nginx’ config file?

I’d like to set: path=/var/www/mysites/

And then reuse this variable, for instance:

root $path/cool_site;

But I can’t figure out how to do it.

set $path /var/www/mysites/;

Hu!? I just figured out I have never tested setting a variable in my
nginx file. I tried it, and it failed: either it is not placed in the
correct area either Nginx complains it doesn’t know about “set”. I am
using Nginx 0.6.31

On Sun, Aug 31, 2008 at 12:56:54PM +0200, Thomas wrote:

Hu!? I just figured out I have never tested setting a variable in my
nginx file. I tried it, and it failed: either it is not placed in the
correct area either Nginx complains it doesn’t know about “set”. I am
using Nginx 0.6.31

It seems that you do not build nginx --with-http_rewrite_module.

Here is an excerpt of my conf file:

set $ngx_path /usr/local/nginx/logs;
set $app_path /home/application;

root $app_path/myblog;
access_log $ngx_path/access.myblog.log;

And here is the error message I get when I start nginx:

2008/09/10 17:01:11 [emerg] 588#0: open()
“/usr/local/nginx/$ngx_path/access.myblog.log” failed (2: No such file
or directory)

Setting a path variable doesn’t work with the log files.

Smashing! Thank you Marcos.

On Wed, Sep 10, 2008 at 05:06:45PM +0200, Thomas wrote:


2008/09/10 17:01:11 [emerg] 588#0: open()
“/usr/local/nginx/$ngx_path/access.myblog.log” failed (2: No such file
or directory)

Setting a path variable doesn’t work with the log files.

access_log supports variables since 0.7.6+ only.

BTW, it’s not good idea to set some variable to static values on server
level and then use them. You may simply define common “root” and
“access_log”
on server level.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs