shell environment variables in "include"-directive not working

Igor Sysoev igor at sysoev.ru
Thu May 13 10:42:37 MSD 2010


On Thu, May 13, 2010 at 12:49:21AM +0200, Markus Grobelin wrote:

> Hy everybody,
> i'm doing my first steps with nginx/0.8.36 and trying to get *NIX shell 
> environment variables working inside the configuration files. Sadly, 
> it's seems they aren't working inside the "include"-directive! :(
> 
> 
> 
> My current (very basic) configuration looks like this:
> 
> # user and group to run as
> user $USER $USER;
> 
> # pid of nginx master process
> pid /nginx/$INSTANCE/run/nginx.pid;
> 
> # number of nginx workers
> worker_processes 2;
> 
> # number of worker connection
> events {
>      worker_connections 1024;
> }
> 
> http {
>      # pull in mime-types
>      include /nginx/INSTANCE/nginx/conf/mime.types;
> 
>      # set a default type for the rare situation that
>      # nothing matches from the mimie-type include
>      #
>      default_type  application/octet-stream;
> 
>      # logging in server-context
>      #
>      access_log /nginx/$INSTANCE/nginx/logs/access.log
>      error_log /nginx/$INSTANCE/nginx/logs/error.log
> }
> 
> 
> When starting the server i got the following messages:
> [alert]: could not open error log file: open() 
> "/var/log/nginx/error.log" failed (13: Permission denied)
> 2010/05/13 00:16:38 [warn] 27977#0: the "user" directive makes sense 
> only if the master process runs with super-user privileges, ignored in 
> /nginx/wally1-dach-static/nginx/conf/nginx.conf:2
> 2010/05/13 00:16:38 [emerg] 27977#0: open() 
> "/nginx/$INSTANCE/nginx/conf/mime.types" failed (2: No such file or 
> directory) in /nginx/wally1-dach-static/nginx/conf/nginx.conf:18
> 
> 
> 
> The [emerg] indicates, that the $INSTANCE environment variable isn't 
> expanded, whereas the "user" and "pid" directive doesn't raise an 
> exception??

As Maxim already said, nginx does not support environment variables.
However, your configuration can be set by running

   nginx -p /nginx/$INSTANCE/ -g "user $USER $USER;"

and using relative paths in configuration:

      pid        run/nginx.pid;
      access_log nginx/logs/access.log;
      error_log  nginx/logs/error.log;


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list