dimanche 30 juin 2019

Docker - Nginx - Laravel: unable to load image, js, css 404

So, I've been working on this for quite a while, I'm not sure where is the problem lies (docker, Nginx or laravel) - so I have laravel file structure like this:

enter image description here

I dont have issue accessing *.php files (e.g. http://localhost:8888/css/phpinfo.php --> this work fine)

but other than that, I can't access my css file (app.css), my js (app.js), and even my images (in images folder) --> it return me 404

so i did a quick check in docker, i go inside docker: docker exec -t -i container_name /bin/bash goto to the respective folder and list it, all looks good (the files are there):

enter image description here

so why i received 404, and my site, just show a plain html (processed from PHP) without any js, css and image.

here is my nginx vhost.conf:

server {
    listen 80;
    index index.php index.html;
    root /var/www/public;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location / {
        try_files $uri /index.php?$args;
    }

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

here is my docker compose file:

version: '3.7'

services:
  # The Web Server
  web:
    container_name: emm_web
    build:
      context: ./
      dockerfile: web.dockerfile
    volumes:
      - ../log/:/var/log
    ports:
      - 8888:80

  # The Database
  database:
    container_name: emm_dat
    image: mysql:5.7
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_HOST=localhost"
      - "MYSQL_PORT=33061"
      - "MYSQL_DATABASE=bdb"
      - "MYSQL_USER=busr"
      - "MYSQL_PASSWORD=pass"
      - "MYSQL_ROOT_PASSWORD=word"
    ports:
      - "33061:3306"

  # The PHP Application
  app:
    container_name: emm_app
    build:
      context: ./
      dockerfile: app.dockerfile
    volumes:
      - ../www/:/var/www
    depends_on:
      - web
      - database
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

volumes:
  dbdata:

what's went wrong here?

here is the access log that show 404:

172.18.0.1 - - [30/Jun/2019:15:34:01 +0000] "GET /images/logo.png HTTP/1.1" 404 37828 "http://localhost:8888/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:34:01 +0000] "GET /css/app.css HTTP/1.1" 404 37764 "http://localhost:8888/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:34:03 +0000] "GET /images/bg.jpg HTTP/1.1" 404 37803 "http://localhost:8888/register" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:36:42 +0000] "GET / HTTP/1.1" 200 40898 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:37:40 +0000] "GET / HTTP/1.1" 200 41275 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:38:54 +0000] "GET /css/info.php HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:39:09 +0000] "GET /css/phpinfo.php HTTP/1.1" 200 92428 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"
172.18.0.1 - - [30/Jun/2019:15:39:19 +0000] "GET /css/app.css HTTP/1.1" 404 37830 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170"



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2YkScM5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire