E
E
EvgMul2020-11-17 11:16:43
Nginx
EvgMul, 2020-11-17 11:16:43

Why am I getting ERR_EMPTY_RESPONSE?

Hello.
I am learning Docker and trying to deploy a project on it.
I got the following configuration:
Dockerfile:

# Базовый образ с nginx и php
FROM richarvey/nginx-php-fpm

# Добавляем наше веб приложение
ADD app /var/www/app

# Удаляем конфиги сайтов которые там есть
RUN rm -Rf /etc/nginx/sites-enabled/*

docker-compose.yml
# Последняя версия docker-compose
version: '3'

# Создаем общую сеть deafult для всех контейнеров
networks:
  default:
    driver: bridge

# Создаем отдельные контейнеры
services:
  # Контейнер с веб-приложением
  app:
    # Собираем из Dockerfile 
    build: 
      # Корнем указываем корень основного проекта
      context: ../
      dockerfile: ./docker/Dockerfile
    # Показываем наружу 80 порт
    ports: 
      - "8000:8000"
    expose:
      - "8000"
    # Подключаем к общей сети с другими контейнерами
    networks: 
      - default
    # Запускаем только после db
    depends_on: 
      - db    
    # Линкуем внешнюю папку с исходниками внутрь
    volumes:
      - "../app:/var/www/app"
      # Так же линкуем конфиг для nginx
      - "./conf/nginx:/etc/nginx/sites-available"      
  # Контейнер с базой данных
  db:
    image: mysql:latest
    # Подключаем к общей сети с другими контейнерами
    networks: 
      - default
    # Показываем наружу порт
    ports:
      - "3336:3306"
    # Задаем параметры для инициализации БД
    environment:
      # Пароль к БД
      MYSQL_ROOT_PASSWORD: root
      # Создаваемая по умолчанию бд
      MYSQL_DATABASE: yii-template-db
    # Линкуем внешнюю папку для хранения БД
    volumes:
      - "./database:/var/lib/mysql"

nginx.conf
server {
    charset utf-8;
    client_max_body_size 128M;

    listen 8000; ## listen for ipv4

    root        /var/www/app/web/;
    index       index.php;

    access_log  /var/www/app/log/frontend-access.log;
    error_log   /var/www/app/log/frontend-error.log;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        try_files $uri =404;
    }

    location ~* /\. {
        deny all;
    }
}


As a result, when accessing, localhost:8000I get an error ERR_EMPTY_RESPONSE
5fb386d01674c534142264.png

Tell me, please, what is my mistake?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tyazhik, 2021-10-11
@Tyazhik

Apparently, the host ip is not correctly specified in the application itself. As I understand it, if you write localhost(127.0.0.1) , then the application listens to the port exactly inside the container, and not outside. To fix the problem, in the application config (or elsewhere if you have a hardcode) you need to change localhost to 0.0.0.0 .
https://forums.docker.com/t/can-access-container-f...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question