nginx’“map”指令中的参数数量无效

我正在尝试反向代理一个websocket,我之前用nginx做过没有问题.奇怪的是,我似乎无法通过如此简单的事情重新创造我之前的成功.我已经遍历配置文件,但似乎无法找到我的错误.

这是我的完整default.conf:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
  listen 80;

  location /api/ {
    proxy_pass ${API_LOCATION};
  }

  location / {
    proxy_pass ${UI_LOCATION};
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }
}

我得到的错误:

2016/10/10 23:30:24 [emerg] 8#8: invalid number of arguments in "map" directive in /etc/nginx/conf.d/default.conf:1
nginx: [emerg] invalid number of arguments in "map" directive in /etc/nginx/conf.d/default.conf:1

我正在使用的确切Dockerfile,以防你想要复制我的设置(将default.conf保存为相对于Dockerfile的conf.templates / default.conf:

FROM nginx
COPY conf /etc/nginx/conf.templates
CMD /bin/bash -c "envsubst < /etc/nginx/conf.templates/default.conf > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

envsubst命令替换所有出现的$vars,包括$http_upgrade和$connection_upgrade.
您应该提供要替换的变量列表,例如:

 envsubst '${API_LOCATION},${UI_LOCATION}' < /etc/nginx/conf.templates/default.conf

另见:Replacing only specific variables with envsubst

此外,在docker-compose配置中,您应该使用double $$转义来禁用变量替换:

FROM nginx
COPY conf /etc/nginx/conf.templates
CMD /bin/bash -c "envsubst '$${API_LOCATION},$${UI_LOCATION}' < /etc/nginx/conf.templates/default.conf > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。