簡體   English   中英

Docker php 8 nginx 配置

[英]Docker php 8 nginx configuration

我嘗試將 PHP 8 添加到我的 docker 項目中,但無法運行它。 我的錯誤可能在 nginx 配置文件中。

文件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配置文件:

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;
    }
  }
}

就我而言, grafanaclickhouse有效。 但是phpfpm不起作用。 在這種情況下如何修復 nginx 配置? 在這種情況下,也許我還必須為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.

嘗試運行此代碼:

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

確保您的 php-fpm 正在運行。 並且還將 fastcgi_pass phpfpm:9000替換為fastcgi_pass 127.0.0.1:9000

請參閱文章: 如何使用 Docker 設置 PHP 8、NGINX、PHP-FPM 和 Alpine

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM