【问题标题】:Error 404 with files created by my Laravel application我的 Laravel 应用程序创建的文件出现错误 404
【发布时间】:2021-04-03 11:53:09
【问题描述】:

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

时间戳为 10:44 的所有文件都来自 git clone。 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;
} }

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

【问题讨论】:

    标签: laravel docker nginx http-status-code-404


    【解决方案1】:

    最后,这是我自己愚蠢的新手错误...问题是我没有将数据保存在 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 帮助我!

    【讨论】:

    • 不错!我花了5个小时才得到这个答案!!! :) 谢谢
    • @Por,很高兴看到它对某人有帮助 :)
    猜你喜欢
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2021-12-31
    • 2020-10-11
    相关资源
    最近更新 更多