File Not Found - Nginx in Docker

烂漫一生 提交于 2020-07-22 05:52:28

问题


Description

I have a docker container with this

nginx.conf

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

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

docker-compose.yaml

version: '2'
services:

  # The Application
  app:
    build:
      context: ./
      dockerfile: app.dockerfile
    working_dir: /var/www
    volumes:
      - ./:/var/www
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

  # The Web Server
  web:
    build:
      context: ./
      dockerfile: web.dockerfile
    working_dir: /var/www
    volumes_from:
      - app
    ports:
      - 85:80

  # The Database
  database:
    image: mysql:5.6
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_DATABASE=homestead"
      - "MYSQL_USER=homestead"
      - "MYSQL_PASSWORD=secret"
      - "MYSQL_ROOT_PASSWORD=secret"
    ports:
        - "33062:3306"

volumes:
  dbdata:

The docker seems to build and start successfully

docker-compose up -d
docker_app_1 is up-to-date
docker_database_1 is up-to-date
Recreating docker_web_1 ... 
Recreating docker_web_1 ... done

but I kept getting

File not found.

How would one go about debugging this?


回答1:


All volumes and other directory settings ideally point to the same location. In your nginx.conf you have root /var/www/public; but in your yal you use /var/www. That might be you problem.

As for steps to proceed, you can check what directories your service actually uses by using the command the following command after you spin up your docker-compose.yml file : docker-compose exec yourServiceName sh

replace yourServiceName with any service you have defined in your yaml. So app , web or database in your yaml above. And that command will take you into the shell (sh) of the container speicified. You can also replace sh with other commands to perform other actions with your container.




回答2:


start your container with docker exec -it xxxxxx bash

once you do that you will be inside the container. Now check your files if they are at the location you are putting them according to your docker-compose file.



来源:https://stackoverflow.com/questions/47115816/file-not-found-nginx-in-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!