title: NGINX: set_by_lua doesn't work
body: <p>I have NGINX running as a proxy service and want to set SSL key depending on the <code>$ENV</code> variable (in Docker Compose file).</p>
  
  <p>I added to the <code>nginx.conf</code>:</p>
  
  <pre><code>env ENVKEY;
  </code></pre>
  
  <p>And then in the config file:</p>
  
  <pre><code>server {
  
      resolver 10.0.0.4 valid=300s;
      resolver_timeout 60s;
  
      server_name  _;
  
      listen 443;
  
      ssl on;
  
  #    perl_set $envkey 'sub { return $ENV{"ENVKEY"}; }';
      set_by_lua $envkey 'return os.getenv("ENVKEY")';
  
      ssl_certificate /etc/nginx/ssl/jm-website-$envkey.crt;
      ssl_certificate_key /etc/nginx/ssl/jm-website-$envkey.key;
  </code></pre>
  
  <p>I also tried to use <code>perl_set</code> - but it can be used in the <code>location</code> only, but <code>ssl_certificate</code> - in the <code>http</code> or <code>server</code> blocks.</p>
  
  <p>Using <code>set_by_lua</code> - I have an error:</p>
  
  <blockquote>
    <p>nginx: [emerg] BIO_new_file("/etc/nginx/ssl/jm-website-$envkey.crt")
    failed (SSL: error:02001002:system library:fopen:No such file or
    directory:fopen('/etc/nginx/ssl/jm-website-$envkey.crt','r')
    error:2006D080:BIO routines:BIO_new_file:no such file)</p>
  </blockquote>
  
  <p>Although variable present in the environment:</p>
  
  <pre><code>root@d0718b0a3361:/etc/nginx# echo $ENVKEY
  dev
  </code></pre>
  
  <p>What I'm doing wrong here?
  Maybe there is better approach?</p>