AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 961807
Accepted
BentCoder
BentCoder
Asked: 2019-04-07 04:34:23 +0800 CST2019-04-07 04:34:23 +0800 CST 2019-04-07 04:34:23 +0800 CST

Não é possível enviar logs de erro php7.3 fpm-alpine para std dentro de contêineres docker

  • 772

Não consigo fazer com que os logs de erro do php-fpm apareçam no docker std. Até agora eu tentei muitas sugestões, mas por algum motivo nenhum progresso. Estou postando toda a minha configuração para que alguém possa gentilmente me ajudar na direção certa. Tudo que eu vejo éapp_php_1 | 172.21.0.7 - 06/Apr/2019:12:26:37 +0000 "GET /index.php" 500

PHP-FPM

Dockerfile

FROM php:7.2.13-fpm-alpine3.8

RUN apk update \
 && apk add --no-cache $PHPIZE_DEPS \
    bash git zip unzip

RUN docker-php-ext-install opcache
RUN docker-php-ext-enable opcache

RUN rm -rf /var/cache/apk/*

COPY php.ini /usr/local/etc/php/conf.d/php.override.ini
COPY www.conf /usr/local/etc/php-fpm.d/www.conf

WORKDIR /app

CMD ["php-fpm", "--nodaemonize"]

php.ini

[php]
date.timezone=UTC
log_errors=On
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors=Off
max_execution_time=60
memory_limit=256M

[opcache]
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
realpath_cache_size=4096K
realpath_cache_ttl=600

www.conf

[global]
daemonize=no

[www]
user=www-data
group=www-data

listen=app_nginx:9000

pm=dynamic
pm.max_children=30
pm.start_servers=2
pm.min_spare_servers=2
pm.max_requests=1000

NGINX

Dockerfile

FROM nginx:1.15.8-alpine

RUN apk add --no-cache bash

RUN rm -rf /var/cache/apk/*

COPY app.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY app_ssl.crt /etc/ssl/certs/app_ssl.crt
COPY app_ssl.key /etc/ssl/private/app_ssl.key

app.conf

server {
    listen 80;

    server_name localhost;

    root /app/public;

    listen 443 default_server ssl;
    ssl_certificate /etc/ssl/certs/app_ssl.crt;
    ssl_certificate_key /etc/ssl/private/app_ssl.key;

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

    location ~ ^/index\.php(/|$) {
        fastcgi_pass app_php:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_hide_header X-Powered-By;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }
}

nginx.conf

user nginx;

worker_processes 2;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;

    use epoll;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format json_combined escape=json
      '{'
        '"time_local":"$time_local",'
        '"remote_addr":"$remote_addr",'
        '"remote_user":"$remote_user",'
        '"request":"$request",'
        '"status": "$status",'
        '"body_bytes_sent":"$body_bytes_sent",'
        '"request_time":"$request_time",'
        '"http_referrer":"$http_referer",'
        '"http_user_agent":"$http_user_agent"'
      '}';

    access_log /var/log/nginx/access.log json_combined;

    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;

    keepalive_timeout 65;

    server_tokens off;

    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection '1; mode=block';
    add_header X-Frame-Options DENY;
    add_header Strict-Transport-Security 'max-age=31536000; includeSubdomains; preload';
    add_header 'Referrer-Policy' 'no-referrer-when-downgrade';

    types_hash_max_size 2048;

    gzip on;

    include /etc/nginx/conf.d/*.conf;
}

docker-compose.yml

version: "3"

services:
  app_php:
    build:
      context: "./php"
    volumes:
      - "../..:/app:consistent"
  app_nginx:
    build:
      context: "./nginx"
    ports:
      - "5080:80"
      - "5443:443"
    volumes:
      - "../..:/app:consistent"
    depends_on:
      - "aapp_php"

O QUE EU TENTEI

Eu tentei isso independentemente um do outro/arquivo, nem tudo de uma vez.

  • Alterado /proc/self/fd/2para /dev/stdout/ /dev/stderrfor error_loge access.logpropriedades no /usr/local/etc/php-fpm.d/docker.confarquivo.

  • Código adicionado abaixo na parte inferior do www.confarquivo.

catch_workers_output = yes
php_flag[display_errors] = off
php_admin_flag[log_errors] = on
php_admin_value[error_log] = /var/log/php-fpm-error.log
php_admin_value[error_log] = /dev/stdout
php_admin_value[error_log] = /dev/stderr
  • Alguns mais, mas perdi a noção.
logging
  • 1 1 respostas
  • 6373 Views

1 respostas

  • Voted
  1. Best Answer
    BentCoder
    2019-05-27T01:53:24+08:002019-05-27T01:53:24+08:00

    Isso parece estar funcionando agora. Eu simplifiquei neste exemplo para mantê-lo fácil nos olhos.


    my_php_1    | [26-May-2019 09:40:40] NOTICE: fpm is running, pid 1
    my_php_1    | [26-May-2019 09:40:40] NOTICE: ready to handle connections
    my_php_1    | 172.22.0.3 -  26/May/2019:09:40:51 +0000 "GET /index.php" 500
    my_nginx_1  | 172.22.0.1 - - [26/May/2019:09:40:51 +0000] "GET / HTTP/1.1" 500 5 "-" "curl/7.38.0" "-"
    my_nginx_1  | 2019/05/26 09:40:51 [error] 8#8: *1 FastCGI sent in stderr: "PHP message: PHP Parse error:  syntax error, unexpected end of file, expecting ',' or ';' in /app/index.php on line 4" while reading response header from upstream, client: 172.22.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.22.0.2:9000", host: "0.0.0.0:1080"
    my_php_1    | [26-May-2019 09:40:51] WARNING: [pool www] child 8 said into stderr: "NOTICE: PHP message: PHP Parse error:  syntax error, unexpected end of file, expecting ',' or ';' in /app/index.php on line 4"
    my_php_1    | 172.22.0.3 -  26/May/2019:09:42:49 +0000 "GET /index.php" 200
    my_nginx_1  | 172.22.0.1 - - [26/May/2019:09:42:49 +0000] "GET / HTTP/1.1" 200 12 "-" "curl/7.38.0" "-"
    my_nginx_1  | 172.22.0.1 - - [26/May/2019:09:42:56 +0000] "GET /no.php HTTP/1.1" 404 153 "-" "curl/7.38.0" "-"
    

    docker-compose.yaml

    version: "3.4"
    
    services:
    
      my_php:
        build:
          context: "./php"
        volumes:
          - "..:/app"
    
      my_nginx:
        build:
          context: "./nginx"
        ports:
          - "1080:80"
        volumes:
          - "..:/app"
        depends_on:
          - "my_php"
    

    PHP

    Dockerfile

    FROM php:7.2.13-fpm-alpine3.8
    
    WORKDIR /app
    
    COPY php.ini /usr/local/etc/php/conf.d/php.override.ini
    COPY www.conf /usr/local/etc/php-fpm.d/www.conf
    
    CMD ["php-fpm", "--nodaemonize"]
    

    php.ini

    [PHP]
    date.timezone=UTC
    log_errors=On
    error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
    display_errors=Off
    max_execution_time=60
    memory_limit=256M
    

    www.conf

    [global]
    daemonize=no
    
    [www]
    user=www-data
    group=www-data
    
    listen=my_nginx:9000
    
    pm=dynamic
    pm.max_children=40
    pm.start_servers=2
    pm.min_spare_servers=2
    pm.max_spare_servers=4
    pm.max_requests=500
    

    NGINX

    Dockerfile

    FROM nginx:1.15.8-alpine
    
    WORKDIR /app
    
    COPY app.conf /etc/nginx/conf.d/default.conf
    COPY nginx.conf /etc/nginx/nginx.conf
    

    app.conf

    server {
        listen 80 default_server;
    
        server_name localhost;
    
        root /app;
    
        index index.php;
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass my_php:9000;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }
    

    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 {
        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;
    
        keepalive_timeout 65;
    
        include /etc/nginx/conf.d/*.conf;
    }
    

    • 3

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve