Ruby Forum NGINX > Set a variable in configuration file

Posted by Thomas (Guest)
on 09.07.2008 01:36
(Received via mailing list)
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.
Posted by Marcos Neves (Guest)
on 09.07.2008 05:20
(Received via mailing list)
set $path /var/www/mysites/;
Posted by Thomas (Guest)
on 09.07.2008 12:05
(Received via mailing list)
Smashing! Thank you Marcos.
Posted by Thomas (Guest)
on 31.08.2008 13:04
(Received via mailing list)
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
Posted by Igor Sysoev (Guest)
on 01.09.2008 07:20
(Received via mailing list)
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.
Posted by Thomas (Guest)
on 10.09.2008 17:17
(Received via mailing list)
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.
Posted by Igor Sysoev (Guest)
on 11.09.2008 22:48
(Received via mailing list)
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.