php - 使PHP和Nginx Docker镜像协同工作

标签 php nginx docker docker-compose

我尝试了许多建议,但无法使其正常工作。
我想与docker-compose.yml合作创建一个NGINX-PHP文件。

这是我做的:

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图像运行没有错误,但是当我想访问Nginx时,我得到了:

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.



我试图登录到两个图像并检查卷。我还检查了是否可以从php ping nginx。一切似乎都很好...

这是我的Nginx站点配置:
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;
    }
}

最佳答案

您默认使用默认服务器配置,因此您需要覆盖默认的nginx虚拟主机:

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

使用它并删除启用站点的卷和可用站点的卷

关于php - 使PHP和Nginx Docker镜像协同工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44188945/

相关文章:

docker - 向 docker 镜像添加新入口点

php 更新 mysql 表每一列中的日期,以便它们自动增加一天

php - MYSQL - 如何用相同的值替换为?

docker - 无法在命令行上访问Docker容器文件夹

php - Nginx 添加 headers PHP FPM 返回错误

oracle - Kubernetes 负载均衡器 Oracle Cloud NGINX 入口 Controller 问题

docker - 无法在 docker debian :jessie 中安装软件包

PHP - 根据星期几在 ID 上设置类

php - $_GET 和 WordPress

docker - Kubernetes 服务选择器更改不会对连接的客户端生效