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

我找不到我的文件index.php放在哪里,因此ngnix可以解释我的文件。 所有容器都在工作,当我放new mysqli时,nginx可以工作 这是我的docker-compose.yml

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli(); // values coming from INI file
$mysqli->set_charset('utf8mb4'); // always set the charset

有人可以帮我吗

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

您需要为PHP和Nginx泊坞映像安装相同的卷。

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.git
cd dockerize-nginx-php;
docker-compose up

现在打开浏览器

http://localhost/helloworld.php

本文链接:https://www.f2er.com/1989604.html

大家都在问