nginx:使用环境变量 [英] nginx: use environment variables

查看:557
本文介绍了nginx:使用环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:我定义了一个env变量$SOME_IP,并想在nginx块中使用它.参考 nginx文档,我在nginx.conf文件中使用env指令,如下所示:

I have the following scenario: I have an env variable $SOME_IP defined and want to use it in a nginx block. Referring to the nginx documentation I use the env directive in the nginx.conf file like the following:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

env SOME_IP;

现在,我想将变量用于proxy_pass.我尝试了如下操作:

Now I want to use the variable for a proxy_pass. I tried it like the following:

location / {
    proxy_pass http://$SOME_IP:8000;
}

但是我最终收到以下错误消息:nginx: [emerg] unknown "some_ip" variable

But I end up with this error message: nginx: [emerg] unknown "some_ip" variable

推荐答案

正确的用法是$SOME_IP_from_env,但是从nginx.conf设置的环境变量不能在服务器,位置或http块中使用.

The correct usage would be $SOME_IP_from_env, but environment variables set from nginx.conf cannot be used in server, location or http blocks.

如果使用包含Lua的 openresty捆绑包,则可以使用环境变量.

You can use environment variables if you use the openresty bundle, which includes Lua.

这篇关于nginx:使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆