我正在尝试反向代理一个websocket,我之前用nginx做过没有问题。奇怪的是,我似乎无法通过如此简单的事情重新创造我之前的成功。我一直在配置文件上,但似乎无法找到我的错误。
这是我的完整$ clang++ -stdlib=libc++ -v ohhello.cpp
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin
"/usr/bin/clang++" -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name ohhello.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/3.8.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /usr/home/mike/projects/ohhello -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/ohhello-050a75.o -x c++ ohhello.cpp
clang -cc1 version 3.8.0 based upon LLVM 3.8.0 default target x86_64-unknown-freebsd11.0
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/v1
/usr/bin/../lib/clang/3.8.0/include
/usr/include
End of search list.
"/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/ohhello-050a75.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
:
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;
}
}
我正在使用的确切Dockerfile,以防你想要复制我的设置(相对于Dockerfile保存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
为default.conf
:
conf.templates/default.conf
答案 0 :(得分:18)
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
配置中,您应该使用双$$
转义来禁用变量替换:
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;'"