【问题标题】:Docker Azure host not found in upstream "php" in /etc/nginx/nginx.conf在 /etc/nginx/nginx.conf 的上游“php”中找不到 Docker Azure 主机
【发布时间】:2021-02-15 11:42:07
【问题描述】:

我有这个问题,当我在本地运行 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 但这不起作用。有什么想法吗?

docker-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 Dockerfile:

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 Dockerfile:

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;

}

【问题讨论】:

    标签: azure docker nginx docker-compose nginx-config


    【解决方案1】:

    如果您使用 docker-compose,所有服务都将创建一个网络,通过该网络它们可以通过容器名称(例如“php”)进行通信。

    如果您使用其他机制(您的问题没有详细说明如何配置 Azure 实例),您必须确保:

    • 您创建一个可以将容器附加到的网络(例如docker network create my-network
    • 使用名称“php”创建后端容器并附加到您的网络(例如docker run --name php --network my-network <image>
    • 如果您已经启动了一个容器,您仍然可以将它附加到网络:docker network connect my-network php

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 2021-10-01
    • 1970-01-01
    • 2020-07-08
    • 2018-03-03
    • 2020-11-09
    • 2020-11-08
    • 2019-09-01
    相关资源
    最近更新 更多