Docker Community Forums

Share and learn in the Docker community.

Configure nginx to serve static files from a folder in another container

Currently I have nginx set up so that it serves static files from a folder in nginx container and .php files from a folder in php-fpm container via fastcgi, like so:

server {
    server_name mysite.test;

    root /app;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/index.php;

    location ~ \.php$ {
        # fastcgi_pass [PHP_FPM_LINK_NAME]:9000;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi.conf;

In this setup I have to mount the same project folder from my host machine to both nginx and pgp-fpm containers. Is there a way to configure nginx so that it accessed both static files and php files located in a folder in php-fpm container?

I tried replacing try_files $uri $uri/index.php; with proxy_pass app:9000; in the location / block, but it didn’t work.