簡體   English   中英

在 /etc/nginx/nginx.conf 的上游“php”中找不到 Docker Azure 主機

[英]Docker Azure host not found in upstream "php" in /etc/nginx/nginx.conf

我有這個問題,當我在本地運行 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;

}

如果您使用 docker-compose,所有服務都將通過網絡創建,通過該網絡它們可以通過容器名稱(例如“php”)進行通信。

如果您使用某種其他機制(您的問題沒有詳細說明如何配置 Azure 實例),則必須確保:

  • 您創建一個網絡,您可以將容器連接到該網絡(例如docker network create my-network
  • 后端容器使用名稱“php”創建並附加到您的網絡(例如docker run --name php --network my-network <image>
  • 如果你已經啟動了一個容器,你仍然可以將它連接到網絡: docker network connect my-network php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM