我的 Laravel 应用程序创建的文件出现错误 404

Error 404 with files created by my Laravel application

我的文件上传有问题。我使用表格上传图片,如果我检查文件夹,我可以看到它并且一切似乎都是正确的:

所有带有时间戳 10:44 的文件都来自 git 克隆。在 10:55 创建的文件来自表单。我可以使用正确的 URL 访问所有这些,除了来自 10:55 的那个,无论我做什么,它都会给我一个 404 错误。

更多信息:一切都在 Digital Ocean 中,docker,我显示的文件夹是提供文件的文件夹。

此外,这是我的 nginx 配置,以防万一:

server {
listen 80;
index index.php index.html;
root /var/www/public;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
# set client body size to 16M #
client_max_body_size 16M;

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

我试过很多东西,但没有办法。任何的想法?谢谢!

最后,是我自己的愚蠢的新手错误...问题是我没有将数据持久化到docker容器之外,所以当我上传图像时,它只存储在应用程序容器中,使其对主机或 nginx 容器不可见,因此解决方案就像在主机中持久化数据并使其可从容器访问一样简单:

services:

  app:
    container_name: laravel_app
    build:
      context: ./
      dockerfile: development/app.dockerfile
    volumes:
      - ./storage:/var/www/storage
      - ./public/images:/var/www/public/images
    env_file: '.env.dev'
    environment:
      - "DB_HOST=database"
      - "REDIS_HOST=cache"

  web:
    container_name: nginx_server
    build:
      context: ./
      dockerfile: development/web.dockerfile
    volumes:
      - ./storage/logs/:/var/log/nginx
      - ./public/images:/var/www/public/images
    ports:
      - 80:80

我刚刚在每个“卷”部分添加了第二行,一切都开始正常工作。我把它留在这里以防它可以帮助 Laravel + Docker + Nginx 中的另一个新手。感谢@amit dahiya 帮助我!