我在Rancher堆栈中有两个容器。一个是为应用程序提供服务的php-fpm容器。第二个是 Nginx 充当反向代理。
nginx 安装了以下配置:
/etc/nginx/nginx.conf
user nginx;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
open_file_cache max=100;
}
/etc/nginx/conf.d/default.conf
server {
...
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_param HTTP_PROXY "";
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
php
在容器升级之前一切正常。从那一刻起,反向代理返回502 Bad Gateway
。错误日志中记录了以下消息:
*5 connect() failed (113: Host is unreachable) while connecting to upstream,
client: 10.42.154.177, server: [hidden url],
request: "GET / HTTP/1.1", upstream: "fastcgi://10.42.241.63:9000",
host: "[hidden-url]"
因此,nginx 不使用主机名,而是直接使用 IP,这显然在容器升级期间会发生变化。如何使这项工作,总是?
我可以创建健康检查,以便重新创建 nginx 容器,但是我的错误日志会被消息淹没。