-1

Please help me. There was an error, a minor error. Maybe I just do not see it, but I had no idea. The essence of the problem: I am setting up a docker environment. Brought nginx, fpm. When url get a php file, nginx return 502.

Structure:

/www
 /app
   /index.php
   /index.html
 /data
   /db
 /etc
   /nginx
      default.conf
   /php
      php.ini
      php-fpm.conf
  1. Compose + env:
version: '3.5'
services:
    nginx:
        image: nginx:alpine
        volumes:
            - "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
            - "./etc/ssl:/etc/ssl"
            - "./app:/var/www/html"
            - "./etc/nginx/default.template.conf:/etc/nginx/conf.d/default.template"
        ports:
            - "80:80"
        environment:
            - NGINX_HOST=${NGINX_HOST}
        command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
        restart: always
        depends_on:
            - php
            - mysqldb
            - memcached
        networks:
            - app
    php:
        image: php:${PHP_VERSION}-fpm
        restart: always
        volumes:
            - "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
            - "./etc/php/php-fpm.conf:/usr/local/etc/php-fpm.conf"
            - "./app:/var/www/html"
        networks:
            - app
        ports:
            - "9000:9000"
        networks:
            - app
    mysqldb:
        image: mysql:${MYSQL_VERSION}
        container_name: ${MYSQL_HOST}
        restart: always
        env_file:
            - ".env"
        environment:
            - MYSQL_DATABASE=${MYSQL_DATABASE}
            - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
            - MYSQL_USER=${MYSQL_USER}
            - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        ports:
            - "3306:3306"
        volumes:
            - "./data/db/mysql:/var/lib/mysql"
        networks:
            - app
    memcached:
        image: memcached:${MEMCACHED_VERSION}
        container_name: ${MEMCACHED_HOST}
        ports:
            - "11211:11211"
        networks:
            - app
networks:
    app:
        driver: bridge
#!/usr/bin/env bash

# See https://docs.docker.com/compose/environment-variables/#the-env-file

# Nginx
NGINX_HOST=localhost

# PHP

PHP_VERSION=5.4

# MySQL
MYSQL_VERSION=5.7.22
MYSQL_HOST=mysql
MYSQL_DATABASE=test
MYSQL_ROOT_USER=root
MYSQL_ROOT_PASSWORD=root
MYSQL_USER=dev
MYSQL_PASSWORD=dev

# Memcached
MEMCACHED_VERSION=latest
MEMCACHED_HOST=memcached
  1. Nginx [/etc/nginx/default.conf]:
upstream phpserver {
    server php:9000;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name localhost;

    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass phpserver;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
  1. PHP [php-fpm.conf]:
[global]

error_log = /proc/self/fd/2
daemonize = no

[www]

; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2

user = www-data
group = www-data

listen = 9000

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
  1. PHP [php.ini] - ini file is default. 5.4. It does not include a user, directories before sessions, etc. Such a structure. More... The phpv should be exactly this (5,4).

What steps did I take to find my error, but did not find:

  • curl localhost:80/index.html >> HELLO_WORLD

  • curl localhost:80/index.php >> 502 nginx

  • netstat -an |grep 9000 >> tcp6 0 0 :::9000 :::* LISTEN

  • curl localhost:80/index.php + docker-compose log >> nginx_1 | 2020/08/26 16:16:09 [error] 7#7: *3 connect() failed (113: Host is unreachable) while connecting to upstream, client: 172.26.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://172.26.0.2:9000", host: "localhost" nginx_1 | 172.26.0.1 - - [26/Aug/2020:16:16:09 +0000] "GET /index.php HTTP/1.1" 502 157 "-" "curl/7.61.1" nginx_1 | 2020/08/26 16:16:09 [info] 7#7: *3 client 172.26.0.1 closed keepalive connection

  • php conteiner root@..:/var/www/html# php index.html *>>* HELLO_WORLD root@..:/var/www/html# php index.php *>>* HELLO_WORLD

  • php conteiner >> root@..:/var/www/html# ls -ll total 13 -rwxrwxrwx. 1 root root 8518 Aug 14 11:36 index.php -rwxrwxrwx. 1 root root 34 Aug 25 21:04 index.html

  • error_log /var/log/nginx/error.log debug; >> cat /var/log/nginx/error.log - empty

Structure www/ - root:root

I'm sorry for wasting time. Please help me. Thank!

mekeind
  • 1
  • 1

1 Answers1

0

I have dealt with the problem. I do not want to write in stages, but I will say it in a nutshell. The problem is caused by the fact that my OS build is centos 8. First of all, the incorrect behavior of containers will show the use of Dockerfile, problems with the repo will be identified. It is possible to solve these problems, but for me it became a trigger, which shows that my environment is not correct. Then I went and installed all the packages for docker as directed for installation under Centos 8.

& see https://computingforgeeks.com/install-docker-and-docker-compose-on-rhel-8-centos-8/

mekeind
  • 1
  • 1