我在DigitalOcean上运行Dokku 0.9.4来托管多个Node.js应用服务器(应用:api
,cms
和www
)。以下是我对新鲜液滴安装的处理方法:
dokku apps:create {app-name}
此时应用程序一直工作,直到我重新启动服务器或执行service docker restart
。在这两种情况发生之后,问题就开始出现了。首先,应用程序根本不可访问一两分钟(当我尝试通过{app-name}.domain.tld
访问任何这些应用程序时,我得到502 Bad gateway
(DNS由Cloudflare处理)。然后,如果它决定几分钟后开始工作应用程序映射似乎混淆了。
例如,如果我尝试打开www.domain.tld
,我实际上会收到来自api
申请的回复,同时打开cms.domain.tld
会返回502 Bad gateway
。
昨天花了整整一天试图查明问题我刚刚设法找到问题的位置,但我不明白为什么会这样。
运行docker networks inspect bridge
会得到以下结果:
[
{
"Name": "bridge",
"Id": "e9edc54047f3d93b9033706d17fd78355440470a090c8010577cfca6ef767946",
"Created": "2017-12-12T09:16:52.784428035Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"Containers": {
"28d7242a146a160dafc94b325439b6385bd49155dec9124e501daf88f8744740": {
"Name": "www.web.1",
"EndpointID": "26f276f07c983755f0baab9999292b23445d4cdf060328e9e1e3cd8914326310",
"MacAddress": "02:42:ac:11:00:05",
"IPv4Address": "172.17.0.5/16",
"IPv6Address": ""
},
"32b2a15f8ccaff48e46f707bb9619d7d106fb18a0632483cc6db341d24d5b606": {
"Name": "cms.web.1",
"EndpointID": "a605bab5af1ec76c802537953b1869116d0ade37bdecf2f76c33c1592ee25b01",
"MacAddress": "02:42:ac:11:00:07",
"IPv4Address": "172.17.0.7/16",
"IPv6Address": ""
},
"500bd73a805ef63d9b2eb4589b3abe4316b72f2d7e029d2dfc71886c6f6fc807": {
"Name": "api.web.1",
"EndpointID": "cd5f8ebd7f2c6dfc8b5828eed1f0a46336415ba8204f9b58270b18ae42aaf357",
"MacAddress": "02:42:ac:11:00:08",
"IPv4Address": "172.17.0.8/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
但是,如果我在nginx.conf
内检查每个应用的/home/dokku/{app-name}/nginx.conf
,我就可以看到问题所在。例如,应用api
包含以下nginx.conf
:
server {
listen [::]:80;
listen 80;
server_name api.tourlyapp.com;
access_log /var/log/nginx/api-access.log;
error_log /var/log/nginx/api-error.log;
location / {
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
gzip_vary on;
gzip_comp_level 6;
proxy_pass http://api-5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
include /home/dokku/api/nginx.conf.d/*.conf;
}
upstream api-5000 {
server 172.17.0.5:5000;
}
,而应用www
包含以下nginx.conf
:
server {
listen [::]:80;
listen 80;
server_name www.tourlyapp.com;
access_log /var/log/nginx/www-access.log;
error_log /var/log/nginx/www-error.log;
location / {
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
gzip_vary on;
gzip_comp_level 6;
proxy_pass http://www-5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
include /home/dokku/www/nginx.conf.d/*.conf;
error_page 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /400-error.html;
location /400-error.html {
root /var/lib/dokku/data/nginx-vhosts/dokku-errors;
internal;
}
error_page 404 /404-error.html;
location /404-error.html {
root /var/lib/dokku/data/nginx-vhosts/dokku-errors;
internal;
}
error_page 500 501 502 503 504 505 506 507 508 509 510 511 /500-error.html;
location /500-error.html {
root /var/lib/dokku/data/nginx-vhosts/dokku-errors;
internal;
}
}
upstream www-5000 {
server 172.17.0.8:5000;
}
除了由于某些原因我不知道www
应用在nginx.conf
内的条目比api
app更多,它还会显示IP混淆了:
www
应用将上游IP地址设置为172.17.0.8
,而此终端由Docker分配给api
应用。
api
应用将上游IP地址设置为172.17.0.8
,它与Docker分配给它的IP地址相同
无论我做什么,IP地址仍然搞砸了(我已经尝试dokku nginx:build-config www
,我尝试制作最简单的Node.js应用程序并且问题仍然存在,我尝试了新的Droplet安装等)。
使所有应用程序正常运行的唯一因素是运行dokku ps:restart {app-name}
。这神奇地使它在下次服务器重启之前有效。
有没有人知道到底出了什么问题,因为我浪费了太多时间试图解决那些应该开箱即用的事情。
答案 0 :(得分:0)
解决方案似乎是将Dokku更新为版本0.11.0
,其中添加了新的插件network
,其中包括在重新启动Docker服务后重建IP地址。
相关问题: