Michael
Michael

Reputation: 1

Multiple dockerised PHP-FPM and Nginx applications

my goal is to get multiple PHP services running. So that I can use the same framework I would copy the code from framework to each service (1 & 2).

tree
├── Framework
│   └── frw.class.php
├── CodeService1
│   └── index.php (rescue frw.class.php)
├── CodeService2
│   └── index.php  (rescue frw.class.php)
├── docker-compose.yml
├── nginx
    ├──conf
       └── myapp.conf
version: '2'

services:

  phpfpm:
    image: 'bitnami/php-fpm:8.0.2'
    container_name: project1
    networks:
      - app-tier
    volumes:
      - ./Framework:/app
      - ./CodeService1:/app/service1

  service2:
    image: 'bitnami/php-fpm:8.0.2'
    container_name: Service1
    networks:
      - app-tier
    volumes:
      - ./Framework:/app
      - ./CodeService2:/app/service2
              
  nginx:
    image: 'bitnami/nginx:latest'
    depends_on:
      - phpfpm
      - service2
    networks:
      - app-tier
    ports:
      - '80:8080'
      - '443:8443'
    volumes:
      - ./nginx/conf/myapp.conf:/opt/bitnami/nginx/conf/server_blocks/myapp.conf

networks:
    app-tier:
        driver: bridge

currently the index-files looks like CodeService1\index.php

<?php declare (strict_types = 1);
echo ("Service1</br>");

CodeService2\index.php

<?php declare (strict_types = 1);
echo ("Service2</br>");

But this won't work. I also tried to outsource the part of create the service (image and copy files) to separates Dockerfiles. but this also won't run.

i call localshost/service1 or localshost/service1 or .

thanks a lot

Upvotes: 0

Views: 348

Answers (1)

Tania Petsouka
Tania Petsouka

Reputation: 1424

Most probable is that in your nginx host you set upstream to phpfpm

set $upstream phpfpm

and that's why CodeService1 only is resolved.

You can set upstream conditionaly, e.g:

# set default to codeservice1
set $upstream phpfpm:9000;

# if service2 url, resolve from service2
if ($request_uri ~ "(^/service2)"){
     set $upstream service2:9000        
}
fastcgi_pass $upstream;

Upvotes: 1

Related Questions