使用 docker nginx 映像时我将 index.php 放在哪里

我找不到放置文件 index.php 的位置,以便 ngnix 可以解释我的文件。所有容器都在工作,当我把localhost:8080nginx 工作时这是我的 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"

谁能帮我吗


达令说
浏览 118回答 1
1回答

摇曳的蔷薇

您需要为 PHP 和 Nginx docker 镜像安装相同的卷。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在主机的文件夹下。树├── app│   ├── helloworld.php│   └── index.php├── docker-compose.yml└── nginx-config    └── default.conf您的 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.gitcd dockerize-nginx-php;docker-compose up现在打开浏览器http://localhost/helloworld.php
打开App,查看更多内容
随时随地看视频慕课网APP