在使用docker nginx图像时,我将index.php放在何处

在使用docker nginx图像时,我将index.php放在何处,php,docker,nginx,docker-compose,Php,Docker,Nginx,Docker Compose,我找不到我把文件index.php放在哪里,这样ngnix就可以解释我的文件了。 所有容器都在工作,当我放置localhost:8080nginx工作时 这是我的docker-compose.yml web: image: nginx volumes: - ./templates:/etc/nginx/templates ports: - "8080:8080" environment: - NGINX_HOST=foobar.com

我找不到我把文件index.php放在哪里,这样ngnix就可以解释我的文件了。 所有容器都在工作,当我放置
localhost:8080
nginx工作时 这是我的docker-compose.yml

web:
  image: nginx
  volumes:
   - ./templates:/etc/nginx/templates
  ports:
   - "8080:8080"
  environment:
   - NGINX_HOST=foobar.com
   - NGINX_PORT=8080

php:
       image: php:7.0-fpm
       expose:
           - 9000
       volumes_from:
           - app
       links:
           - elastic

app:
       image: php:7.0-fpm
       volumes:
           - .:/src

elastic:
       image: elasticsearch:2.3
       volumes:
         - ./elasticsearch/data:/usr/share/elasticsearch/data
         - ./elasticsearch/logs:/usr/share/elasticsearch/logs
       expose:
         - "9200"
       ports:
         - "9200:9200"

有人能帮我吗

您需要为PHP和Nginx docker image装载相同的卷

version: '3'
services:
  nginx:
    image: nginx:alpine
    volumes:
      - ./app:/app
      - ./nginx-config/:/etc/nginx/conf.d/
    ports:
      - 80:80
    depends_on:
      - php
  php:
    image: php:7.3-fpm-alpine
    volumes:
     - ./app:/app

在上面的撰写文件中,代码放在主机的
app
文件夹下

Nginx配置应该使用docker服务网络来连接php fpm容器

server {
    index index.php index.html;
    server_name php-docker.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /app/;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
或者您可以尝试Github的工作示例

git clone https://github.com/Adiii717/dockerize-nginx-php.git
cd dockerize-nginx-php;
docker-compose up
现在打开浏览器


http://localhost/helloworld.php

谢谢您的回复。好的,我从github克隆了这个项目,然后安装了ElasticSearch和composer.json->Vendor is generated,但当我尝试执行“require'../Vendor/autoload.php';“我收到一个错误,说我找不到这个文件”无法打开流:在/app/index.php第4行中没有这样的文件或目录”顺便说一句,首先最好检查helloworld是否正常工作,然后问题就不同了?helloworld和index.php工作得非常好。当我在/app下放置“require”时出现问题,即使我在/app下放置了一个文件似乎require无效
require'../vendor/autoload.php
,vendor folder在哪里?我第一次将vendor安装在/app的父文件夹下。我照你说的做了。然后我在/app下安装了composer.json,然后在第5行/app/test.php中更改为
require'vendor/autoload.php'
这通常是相同的问题
致命错误:require():无法打开required'/vendor/autoload.php'(include_path='。:/usr/local lib/php')
git clone https://github.com/Adiii717/dockerize-nginx-php.git
cd dockerize-nginx-php;
docker-compose up