【发布时间】:2021-12-28 23:01:38
【问题描述】:
我正在使用 nginx lua docker 镜像firesh/nginx-lua:alpine-3.4。我尝试在 nginx.config 文件中使用环境变量。下面是/etc/nginx/nginx.conf中的配置。
user nginx;
env ES_USERNAME;
env ES_PWD;
worker_processes 1;
events {
worker_connections 10240;
}
http {
server {
listen 8080;
server_name localhost;
set_by_lua $es_username os.getenv("ES_USERNAME");
set_by_lua $es_pwd os.getenv("ES_PWD");
location /health {
proxy_pass http://$es_username:$es_pwd@elk-es-http:9200/_cluster/health;
}
...
启动容器后,我在日志中看到此错误:
2021/11/18 01:07:14 [error] 6#6: *6 failed to load inlined Lua code: set_by_lua:1: unexpected symbol near '"http://"', client: 10.0.4.122, server: localhost, request: "GET /health HTTP/1.1", host: "10.0.2.170:8080"
问题是proxy_pass后面的url没有从lua中读取变量。它将${es_username} 视为一个字符串,而不是读取它的值。正确的使用方法是什么?
【问题讨论】: