我正在尝试反向代理一个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.
您应该提供要替换的变量列表,例如:
原文链接:https://www.f2er.com/nginx/434674.html您应该提供要替换的变量列表,例如:
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;'"