doushui5587 2016-08-11 15:58
浏览 279

Docker撰写:Nginx和PHP-FPM无法正常工作

I'm testing docker compose with Nginx and php-fpm, but this fail. My 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:

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

And dafault.conf file:

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:

"File not found."

but, the index.php is in the project/ path.

that I am wrong?

  • 写回答

1条回答 默认 最新

  • dsa45132 2016-08-17 07:11
    关注

    I think you need to use volumes_from in your nginx container in the compose file, now you have in nginx:

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

    And in php

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

    They should be the same.

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题