简体   繁体   中英

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

I have this problem where when I run Docker locally it works, but when I try to run a multi container app on Azure it gives me this error:

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 

It's obviously referring to the fastcgi_pass php:9000; line, I tried using localhost but that didn't work. Any ideas?

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;

}

If you are using docker-compose, all services will be created with a network through which they can communicate by container name (eg "php").

If you use some other mechanism (your question does not go into detail how you configure your Azure instance), you have to make sure that:

  • You create a network to which you can attach your containers (eg docker network create my-network )
  • The backend container is created with the name "php" and attached to your network (eg docker run --name php --network my-network <image> )
  • If you have already started a container you can still attach it to a network: docker network connect my-network php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM