简体   繁体   English

问题 docker-compose 和 laravel nginx 不在生产中工作

[英]Problem docker-compose with laravel nginx not working on production

I wrote a docker-compose.yml with nginx, mysql, and an application laravel with a dockerfile.我用 nginx、mysql 写了一个 docker-compose.yml,用 dockerfile 写了一个应用程序 laravel。

My docker-compose:我的 docker-compose:

version: "3.7"
services:
  app_back:
    build:
  
      context: .
      dockerfile: Dockerfile
    image: dreamy_back   
    container_name: dreamy-back-app
    restart: unless-stopped
    working_dir: /var/www/
    volumes:
      - .:/var/www
    networks:
      - dreamy
  db:
    image: mysql
    container_name: dreamy-db
    restart: unless-stopped
    depends_on:
      - app_back
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: 4ztgeU%
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
    networks:
      - dreamy
  nginx:
    image: nginx:1.17-alpine
    container_name: dreamy-back-nginx
    restart: unless-stopped
    ports:
      - 8000:80
    volumes:
      - ./:/var/www
      - ./docker-compose/vhosts:/etc/nginx/conf.d
    networks:
      - dreamy
networks:
  dreamy:
    driver: bridge

My dockerfile for an laravel application:我的 dockerfile 申请 laravel:

I execute composer install inside the container.我在容器内执行 composer install 。

FROM php:8.1-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory

WORKDIR /var/www

My nginx conf:我的 nginx 配置文件:

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app_back:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

On my laptop it's working but on my vps server I get an error 500.在我的笔记本电脑上它可以正常工作,但在我的 vps 服务器上我收到错误 500。

My docker should be accessible port 8000我的 docker 应该可以访问端口 8000

My nginx logs我的 nginx 日志

UPDATE - I found the problem, in production the application does not display laravel errors.更新 - 我发现了问题,在生产中应用程序不显示 laravel 错误。 So it is the default ngynx page that is displayed.所以显示的是默认的 ngynx 页面。 The error was the right for the storage file.错误是存储文件的权限。

Thank you for your help.谢谢您的帮助。

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

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