简体   繁体   English

Docker php 8 nginx 配置

[英]Docker php 8 nginx configuration

I tried add PHP 8 to my docker project but can't run it.我尝试将 PHP 8 添加到我的 docker 项目中,但无法运行它。 My error maybe in nginx config file.我的错误可能在 nginx 配置文件中。

File docker-compose.yml :文件docker-compose.yml

version: "3.7"

services:
  phpfpm:
    image: php:8.0.2-fpm-alpine3.13
    container_name: phpfpm
    volumes:
      - ./php/src:/var/www/html
      - ./php/config/php.ini:/usr/local/etc/php/conf.d/php.ini
    networks:
      - Project
  nginx:
    image: nginx:latest
    container_name: proxy_nginx
    restart: always
    ports:
      - "8888:8888"
      - "9999:9999"
      - "5555:5555"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/logs:/var/log/nginx/
      - ./php/src:/var/www/html
    depends_on:
      - grafana
      - clickhouse
      - phpfpm
    networks:
      - Project

  clickhouse:
    container_name: clickhouse
    image: yandex/clickhouse-server
    volumes:
      - ./clickhouse/data:/var/lib/clickhouse:rw
      - /var/log/clickhouse-server
      - ./clickhouse/init_schema.sql:/docker-entrypoint-initdb.d/init_schema.sql
      # - ./clickhouse/config.xml:/etc/clickhouse-server/config.xml
    networks:
      - Project
  grafana:
    container_name: grafana
    image: grafana/grafana
    volumes:
      - ./grafana:/var/lib/grafana:rw
      - ./grafana/grafana-clickhouse-datasource.yaml:/etc/grafana/provisioning/datasources/grafana-clickhouse-datasource.yaml
      - ./grafana/grafana-dashboards.yaml:/etc/grafana/provisioning/dashboards/grafana-dashboards.yaml
      - ./grafana/dashboards/:/var/lib/grafana/dashboards/
    environment:
      - GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=vertamedia-clickhouse-datasource
      - GF_INSTALL_PLUGINS=grafana-piechart-panel,grafana-worldmap-panel,vertamedia-clickhouse-datasource
    depends_on:
      - clickhouse
    networks:
      - Project
networks:
  Project:
    driver: bridge

Nginx config file: Nginx配置文件:

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
worker_rlimit_nofile 4096;

events {
  multi_accept on;
  use epoll;
  worker_connections 1024;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  error_log syslog:server=127.0.0.1:8000;
  # error_log /var/log/nginx/error.log warn;
  # access_log /var/log/nginx/access.log;
  access_log syslog:server=127.0.0.1:8000;
  open_file_cache max=5000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  server_tokens off;
  types_hash_max_size 2048;
  keepalive_requests 1000;
  keepalive_timeout 5;
  server_names_hash_max_size 512;
  server_names_hash_bucket_size 64;
  client_max_body_size 100m;
  client_body_buffer_size 256k;
  reset_timedout_connection on;
  client_body_timeout 10;
  send_timeout 2;
  gzip on;
  gzip_static on;
  gzip_comp_level 5;
  gzip_min_length 256;
  gzip_http_version 1.1;
  gzip_proxied any;
  gzip_vary on;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
  gzip_disable "msie6";
  proxy_max_temp_file_size 0;

  upstream proj {
    server clickhouse:8123;
  }

  upstream grafana {
    server grafana:3000;
  }

  server {
    listen 8888;
    server_name 127.0.0.1;
    root /var/www;
    proxy_set_header Host $host;
    location / {
      proxy_pass http://proj;
      proxy_set_header Host $host;
      add_header Cache-Control "no-cache" always;
    }
  }

  server {
    listen 9999;
    server_name 127.0.0.1;
    root /var/www;
    proxy_set_header Host $host;
    location / {
      proxy_pass http://grafana;
      proxy_set_header Host $host;
      add_header Cache-Control "no-cache" always;
    }
  }

  server {
    listen 5555;
    server_name 127.0.0.1;
    index index.php index.html;
    root /var/www/html;

    location / {
      try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass phpfpm:9000;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
    }
  }
}

In my case grafana and clickhouse works.就我而言, grafanaclickhouse有效。 But phpfpm doesn't works.但是phpfpm不起作用。 How I can fix nginx config in this case?在这种情况下如何修复 nginx 配置? Maybe also I must use upstream for phpfpm in this case?在这种情况下,也许我还必须为phpfpm使用上游?

it seems that the Nginx file does not contain any reference to the yaml one, check if the yaml extension is working in php 8 and check also which is the file that parse the yaml document. it seems that the Nginx file does not contain any reference to the yaml one, check if the yaml extension is working in php 8 and check also which is the file that parse the yaml document.

try running this code:尝试运行此代码:

if(function_exists("yaml_parse"))echo "yaml extension is enabled";
else echo "yaml extension is not enabled";

Make sure your php-fpm is running.确保您的 php-fpm 正在运行。 and Also replace fastcgi_pass phpfpm:9000 with fastcgi_pass 127.0.0.1:9000 .并且还将 fastcgi_pass phpfpm:9000替换为fastcgi_pass 127.0.0.1:9000

See the article: How to setup PHP 8, NGINX, PHP-FPM and Alpine with Docker请参阅文章: 如何使用 Docker 设置 PHP 8、NGINX、PHP-FPM 和 Alpine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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