My app files are located in phpfpm container and I need to serve them through nginx. I want to avoid mounting the same files in two containers, so I'm trying to figure out a way to serve them only from one, phpfpm, container. When I use reverse proxy to other containers:
server {
    listen 0.0.0.0:8080;
    server_name myapp.test;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://phpfpm:900;
        proxy_redirect off;
    }
}
I get 502 Bad Gateway error with the following error log record:
1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.18.0.1, server: myapp.test, request: "GET / HTTP/1.1", upstream: "http://172.18.0.2:9000/", host: "myapp.test"
I guess it's because phpfpm container is not a HTTP server.
So, alternatively, I try using fastcgi_pass like so:
server {
    listen 0.0.0.0:8080;
    server_name myapp.test;
    root /app;
    location / {
        try_files $uri $uri/index.php;
    }
    location ~ \.php$ {
        fastcgi_pass phpfpm:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}
This serves *.php files as expected, but doesn't serve other files, namely static content.
How do I makenginx serve both .php and static files from my phpfpm container?
Here's my docker-compose.yml:
version: "3.7"
services:
  phpfpm:
    image: "php-fpm:7.3"
    volumes:
      - ./site:/app
    ports:
      - "9000:9000"
  nginx:
    image: "nginx:1.17"
    volumes:
      - ./nginx/app.conf:/opt/nginx/conf/nginx.conf
    ports:
      - "80:8080"
