Janbalik
Janbalik

Reputation: 594

Error 404 with files created by my Laravel application

I have a problem with the file uploadings. I use a form to upload images and if I check the folder, I can see it and everything seems correct: enter image description here

All the files with timestamp 10:44 come from a git clone. The file created at 10:55 comes from the form. I can access all of them using the right URL, except the one from 10:55, which gives me a 404 error, no matter what I do.

Some more info: Everything is in Digital Ocean, with docker, and the folder I am showing is the one that serves the files.

Also, here is my nginx configuration, just in case:

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

I have tried many things, but no way. Any idea? Thanks!

Upvotes: 0

Views: 1547

Answers (1)

Janbalik
Janbalik

Reputation: 594

Finally, it was my own stupid novice error... The problem was I was not persisting the data outside the docker container, so when I uploaded an image it was stored only in the application container, making it not visible for the host or the nginx container, so the solution was as easy as persisting data in the host and make it accessible from the containers:

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

I just added the second line on each "volumes" section and everything began to work properly. I leave it here in case it could help another novice in Laravel + Docker + Nginx. Thanks @amit dahiya for helping me!

Upvotes: 1

Related Questions