我有这个问题,当我在本地运行 Docker 时它可以工作,但是当我尝试在 Azure 上运行多容器应用程序时,它给了我这个错误:
2020/11/02 19:10:39 [emerg] 1#1: host not found in upstream "php" in /etc/nginx/nginx.conf:38
nginx: [emerg] host not found in upstream "php" in /etc/nginx/nginx.conf:38
这显然是指这fastcgi_pass php:9000;
条线,我尝试使用 localhost 但没有奏效。有任何想法吗?
码头工人-compose.yml:
version: '3.1'
services:
db:
image: mysql:5.7
restart: always
environment:
- MYSQL_ROOT_PASSWORD=password
ports:
- "3306:3306"
php:
image: joelcastillo/php:1.1
ports:
- "9000:9000"
restart: always
web:
image: joelcastillo/nginx:1.3
ports:
- "80:80"
links:
- php
PHP Docker 文件:
FROM php:7-fpm
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install mysqli
RUN usermod -u 1000 www-data
RUN apt-get update && apt-get install -y libpng-dev libmagickwand-dev --no-install-recommends
RUN docker-php-ext-install opcache
RUN docker-php-ext-install gd
RUN pecl install imagick
RUN docker-php-ext-enable imagick
Nginx Docker 文件:
FROM nginx
COPY ./ /code
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
nginx.conf:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 80 default_server;
root /code/public_html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
# Forward images to prod site
location ~ ^/app/uploads {
try_files $uri @prod;
}
location @prod {
rewrite ^/app/uploads/(.*)$ https://jee-o.com/app/uploads/$1 redirect;
}
location ~ \.php$ {
proxy_read_timeout 3600;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
}