0

I am deploying 2 docker containers (nginx and php fpm) in my windows 10 pro local machine.

I can get php script executed correctly.

For example: http://localhost:8888/phpinfo.php --> this return correctly.

But other than php script (e.g. image, js or css) it giving me not found.

For example: http://localhost:8888/image.jpg --> not found

Whats possibly went wrong here?

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 PHP Application
  app:
    container_name: emm_app
    build:
      context: ./
      dockerfile: app.dockerfile
    volumes:
      - ../www/:/var/www
    depends_on:
      - web
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

And here is my nginx vhost.conf:

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

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

Thank you :)

1 Answer 1

2
+100

You need to share files for nginx container. Try this:

# The Web Server
web:
  container_name: emm_web
  build:
    context: ./
    dockerfile: web.dockerfile
  volumes:
    - ../log/:/var/log
    # !! nginx need this volume !!
    - ../www/:/var/www:ro
  ports:
    - 8888:80

That readonly volume will make the files in the container available.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks and it works, but it also work without :ro - any reason why i should put ro?
Nginx needs this files only for reading, thats why i recommend read-only volume.
Old post but you saved me ours :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.