Answers:
通过结合答案,我找到了解决方案。
https://serverfault.com/questions/388552/nginx-sub-domain-proxy-pass
https://stackoverflow.com/questions/35744650/docker-network-nginx-resolver
https://stackoverflow.com/questions/41766195/nginx-emerg-server-directive-is-not-allowed-here
nginx.conf:
events {
}
http {
server {
listen 80;
server_name ~(.*).test.go;
location / {
if ($host ~* ^([a-zA-Z0-9-]+)\.test\.go$) {
set $proxyhost docker-$1:9000;
}
resolver 127.0.0.11 ipv6=off;
proxy_pass http://$proxyhost;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
}
}
}
谢谢
site.conf
server_tokens关闭;
map $ http_upgrade $ connection_upgrade {默认升级;''
关闭; }服务器{
设置$ access_log'var / log / nginx / my-site.access.log'; 设置$ error_log'var / log / nginx / my-site.error.log';
听80; server_name feature-1234.mydomain.com;
access_log / $ access_log; error_log / $ error_log;
位置 / {
proxy_pass docker-feature-1234:9000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; if ($uri != '/') { expires 30d;} access_log /$access_log; } }
贴上
触摸/etc/nginx/sites-available/site.conf
下一个
ln -s /etc/nginx/sites-available/site.conf / etc / nginx / sites-enabled
下一个
服务nginx重新加载
如果您没有root访问权限,则将sudo添加到命令开头