简体   繁体   English

Docker Compose:Nginx和PHP-FPM不起作用

[英]Docker Compose: Nginx and PHP-FPM not working

I'm testing docker compose with Nginx and php-fpm, but this fail. 我正在用Nginx和php-fpm测试docker compose,但这失败了。 My docker-compose.yml: 我的docker-compose.yml:

version: '2'

services:

  nginx:
    container_name: nginx
    build:
      context: ./dockerfiles/nginx/
      dockerfile: Dockerfile
    volumes:
      - ./project/:/usr/share/nginx/html/
    ports:
      - "8000:80"
    links:
      - php

  php:
    container_name: php-fpm
    image: php:7-fpm
    volumes:
      - ./project/:/var/www/html/
    ports:
      - "9000:9000"

This is my dockerfile Nginx: 这是我的dockerfile Nginx:

FROM nginx:latest
COPY config/default.conf /etc/nginx/conf.d/

And dafault.conf file: 和dafault.conf文件:

server {
  listen 80;

  server_name localhost;

  root /usr/share/nginx/html;

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

    location ~ ^/.+\.php(/|$) {
        fastcgi_pass php:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

when I try localhost: 8000 returns the following message: 当我尝试localhost时:8000返回以下消息:

"File not found." “文件未找到。”

but, the index.php is in the project/ path. 但是index.php在项目/路径中。

that I am wrong? 我错了吗?

I think you need to use volumes_from in your nginx container in the compose file, now you have in nginx: 我认为您现在需要在nginx中使用nginx容器中的volumes_from:

volumes:
  - ./project/:/usr/share/nginx/html/

And in php 和在PHP

volumes:
  - ./project/:/var/www/html/

They should be the same. 它们应该是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM