dsfliu1129 2017-05-25 20:03
浏览 69
已采纳

使PHP和Nginx Docker镜像协同工作

I tried many many advises, but can't make it working. I want to create a docker-compose.yml file with NGINX-PHP cooperation.

Here's what I made:

version: "2"

services:
  nginx:
    image: nginx:latest
    restart: always
    ports: 
      - "80:80"
      - "443:443"
    links:
      - php
    depends_on:
      - php
    expose:
      - "80"
      - "443"
    volumes:
      - ./www:/var/www/html
      - ./config/nginx/site.conf:/etc/nginx/sites-available/default
      - ./config/nginx/site.conf:/etc/nginx/sites-enabled/default

  php:
    image: php:7-fpm
    restart: always
    volumes:
      - ./www:/var/www/html

Docker images run without errors, but when I want to access Nginx, I get this:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.

Thank you for using nginx.

I tried to log into both images and check volumes. I also checked if I can ping php from nginx. Everything seems to be fine...

Here's my Nginx site configuration:

server {
    server_name ncp-docker;

    listen 80;
    index index.php index.html index.htm;
    root /var/www/html;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /(inc|uploads/avatars) {
        deny all;
    }
}
  • 写回答

3条回答 默认 最新

  • dongzhou5344 2017-05-25 20:23
    关注

    You are defaulting to default server configuration, so you need to overwrite the default nginx virtual host:

        - ./config/nginx/site.conf:/etc/nginx/conf.d/default.conf
    

    Use that and remove both sites-enabled and sites-available volumes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法