我正在嘗試使用docker在AWS ECS上運行一個php + mysql應用程序。 應用程序堆棧由一個mysql,elk,php-fpm和nginx docker容器組成。這些容器都運行在同一臺碼頭機器上。當任務啓動時,nginx容器退出時出現以下錯誤:nginx:[emerg]主機在/etc/nginx/conf.d/upstream.conf中的上游「php:9001」中找不到:。AWS ECS Docker - nginx:[emerg]主機在上游找不到
Nginx的Dockerfile:
FROM alpine:3.4
RUN apk add --update nginx
#Clear Cache and Temp Data
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/conf.d/
RUN echo "upstream php-upstream { server php:9001; }" > /etc/nginx/conf.d/upstream.conf
RUN adduser -D -g '' -G www-data www-data
CMD ["nginx"]
EXPOSE 80
EXPOSE 443
RUN echo "upstream php-upstream { server php:9001; }" > /etc/nginx/conf.d/upstream.conf
的php:9001
部分引用PHP的容器,其在AWS ECS任務定義定義。
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
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;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
open_file_cache max=100;
}
daemon off;
symfony.conf:
server {
server_name _;
root /var/www/symfony/web;
location/{
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
/etc/php7/php-fpm.conf:
[symfony]
user = nobody
group = nobody
listen = 0.0.0.0:9001
pm = dynamic
pm.max_children = 1000
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE
env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER
env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD
catch_workers_output = yes
我a也試圖改變聽listen = /var/run/php-fpm/php-fpm.sock
或listen = 127.0.0.1:9001
與相應的更改nginx配置,但這導致了各種其他錯誤消息。
您能否擴展此項?我沒有找到你說的選項。 – Borjante