本文介绍了NGINX和环境变量来自配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过配置文件将一些环境变量设置为nginx。我正在使用nginx / 0.8.53,它不工作。

  server {
listen 80;
server_name localdictus;
root / opt / vdmo_dictus / public; #< ---请务必指向'public'!
passenger_enabled on;
rails_env开发;
env VDMO_MANDANT =somevalue;
}

这是错误消息:


$ b /opt/nginx/conf/nginx.conf:43
未知指令env

文档告诉我有一个env命令...所以我在做错什么?



通过导出在shell上设置环境变量不是我的应用程序的选项。



这里是行:

  37:server {
38:listen 80;
39:server_name localdictus;
40:root / opt / vdmo_dictus / public; #< ---请务必指向'public'!
41:passenger_enabled on;
42:rails_env开发;
43:env VDMO_MANDANT =somevalue;
44:}

问候,



Alex

解决方案

env 指令的上下文是 main ,而不是 服务器 。将该指令放在您的服务器{...} 块之外(在任何块之外)。



另请参见。我不相信 env 指令会执行您要查找的内容。


I'm trying to set some environment variables to nginx via it's configuration file. I'm using nginx/0.8.53 and it's not working.

server {
    listen 80;
    server_name localdictus;
    root /opt/vdmo_dictus/public;   # <--- be sure to point to 'public'!
    passenger_enabled on;
    rails_env development;
    env VDMO_MANDANT = "somevalue";
    }

This is the error message:

unknown directive "env" in /opt/nginx/conf/nginx.conf:43

The documentation tells me that there is an "env" command... so what I'm doing wrong ??http://wiki.nginx.org/CoreModule#env

setting the environment variables via export on the shell is not an option for my application by the way.

Here are the lines:

37:    server {
38:    listen 80;
39:    server_name localdictus;
40:    root /opt/vdmo_dictus/public;   # <--- be sure to point to 'public'!
41:    passenger_enabled on;
42:    rails_env development;
43:    env VDMO_MANDANT = "somevalue";
44:    }

Regards,

Alex

解决方案

From the documentation you linked to the "Context" for the env directive is main, not server. Put the directive outside of your server { ... } block (outside of any block).

See also this discussion. I do not believe that the env directive does what you are looking for.

这篇关于NGINX和环境变量来自配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 19:46