我有一个在使用docker-compose构建的docker容器中运行的Symfony应用程序。
我有3个容器,一个用于PHP应用程序,Nginx,一个用于MySQL。
我的问题是提供静态资产,例如上传的文件,还提供来自构建的CSS样式和javascript文件。它只是返回404错误。
这是nginx配置
# ./docker/nginx/default.conf
server {
server_name ~.*;
location / {
root /src/app/public;
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
client_max_body_size 50m;
fastcgi_pass php:9000;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /src/app/public/index.php;
}
error_log /dev/stderr debug;
access_log /dev/stdout;
}
这是我的docker-compose.yml
version: "3.7"
services:
mysql:
command: --default-authentication-plugin=mysql_native_password
image: mysql:8.0
restart: on-failure
environment:
MYSQL_ROOT_PASSWORD: some_passowrd
MYSQL_DATABASE: some_database
ports:
- "3307:3306"
nginx:
image: nginx:1.15.3-alpine
restart: on-failure
depends_on:
- php
volumes:
- "./public/:/src/app"
- "./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro"
ports:
- "8001:80"
php:
build:
context: .
dockerfile: ./docker/php/Dockerfile
restart: on-failure
env_file:
- .env
user: 1000:1000
和我的Symfony应用程序的Dockerfile
# ./docker/php/Dockerfile
FROM php:7.2-fpm
RUN docker-php-ext-install pdo_mysql
RUN pecl install apcu-5.1.8
RUN docker-php-ext-enable apcu
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \ && php composer-setup.php --filename=composer \ && php -r "unlink('composer-setup.php');" \ && mv composer /usr/local/bin/composer
RUN apt-get update && \
apt-get install -y \
zlib1g-dev
RUN docker-php-ext-install zip
RUN chmod +x /usr/local/bin/composer
WORKDIR /src/app
COPY ./ /src/app
RUN PATH=$PATH:/src/app/vendor/bin:bin
我认为它与Nginx设置有关,但是我还无法找到一种解决方法。
有什么建议吗?