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



我写了一篇docker-compose。使用nginx, mysql和一个应用程序和一个dockerfile。

My 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

我的dockerfile for一个laravel应用程序:

我在容器内执行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:

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

在我的笔记本电脑上,它工作,但在我的vps服务器上,我得到一个错误500。

我的docker应该可以访问端口8000

My nginx logs

UPDATE -我发现了问题,在生产中应用程序不显示laravel错误。因此显示的是默认的ngynx页面。错误是正确的存储文件。

谢谢你的帮助。

最新更新