Serve static content using docker + nginx + php-fpm The 2019 Stack Overflow Developer Survey Results Are InBlank Page: wordpress on nginx+php-fpmphpmyadmin having problems on nginx and php-fpm on RHEL 6nginx php5-fpm path_info urls and root locationNGINX don't parse .php5 as .phpDocker PHP-FPM & NGINXNginx php-fpm in docker - Getting 404sDocker - scaling nginx and php-fpm seperatelynginx, php-fpm, and subfoldersCodeIgniter nginx rewrite rules for i8ln URL's502 Bad Gateway with dockerized PHP-FPM

If my opponent casts Ultimate Price on my Phantasmal Bear, can I save it by casting Snap or Curfew?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Deal with toxic manager when you can't quit

How to make Illustrator type tool selection automatically adapt with text length

What is this sharp, curved notch on my knife for?

Why not take a picture of a closer black hole?

Keeping a retro style to sci-fi spaceships?

Didn't get enough time to take a Coding Test - what to do now?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

Is Cinnamon a desktop environment or a window manager? (Or both?)

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

How can I have a shield and a way of attacking at distance at the same time?

Why are there uneven bright areas in this photo of black hole?

How to substitute curly brackets with round brackets in a grid of list

Is it okay to consider publishing in my first year of PhD?

Cooking pasta in a water boiler

Can a flute soloist sit?

How do you keep chess fun when your opponent constantly beats you?

What force causes entropy to increase?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Correct punctuation for showing a character's confusion

Match Roman Numerals

How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?



Serve static content using docker + nginx + php-fpm



The 2019 Stack Overflow Developer Survey Results Are InBlank Page: wordpress on nginx+php-fpmphpmyadmin having problems on nginx and php-fpm on RHEL 6nginx php5-fpm path_info urls and root locationNGINX don't parse .php5 as .phpDocker PHP-FPM & NGINXNginx php-fpm in docker - Getting 404sDocker - scaling nginx and php-fpm seperatelynginx, php-fpm, and subfoldersCodeIgniter nginx rewrite rules for i8ln URL's502 Bad Gateway with dockerized PHP-FPM



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








9















I'm trying to configure a php webapp using docker. The idea is to run the app using php-fpm in a standalone container and have another container that will run nginx. The idea for this setup is to use that same nginx container to proxy requests to other webapps that are already working on the same machine.
The problem is that I can't get nginx to properly process static files (js, css, etc.), as the requests to those keep going to fpm.



This is what the filesystem looks like:



/
├── Makefile
├── config
│ └── webapp.config
└── webapp
└── web
├── index.php
└── static.js


I'm running the whole thing using a Makefile that looks like this (not interested in docker-compose for this):



PWD:=$(shell pwd)
CONFIG:='/config'
WEBAPP:='/webapp'

run: | run-network run-webapp run-nginx

run-network:
docker network create internal-net

run-webapp:
docker run --rm
--name=webapp
--net=internal-net
--volume=$(PWD)$(WEBAPP):/var/www/webapp:ro
-p 9000:9000
php:5.6.22-fpm-alpine

run-nginx:
docker run --rm
--name=nginx
--net=internal-net
--volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
-p 80:80
nginx:1.11.0-alpine


This is what my config/webapp.conf looks like.



server 
listen 80;
server_name webapp.domain.com;

# This is where the index.php file is located in the webapp container
# This folder will contain an index.php file and some static files that should be accessed directly
root /var/www/webapp/web;

location /
try_files $uri $uri/ @webapp;


location @webapp
rewrite ^(.*)$ /index.php$1 last;


location ~ ^/index.php(/


Whatever action that needs to get processed using that index.php file will work. However, static files won't be served, resulting in nasty 404 errors (as the php webapp doesn't really have routes configured for those). I believe nginx tries to load those from its own container filesystem, when they are actually in the webapp container, failing back into @webapp.



Is there a way I can configure nginx to serve those files that reside in another container?










share|improve this question
















bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 3





    Are you using docker to isolate nginx from php applications while requiring that nginx has access to files within the php applications?

    – Stefan Schmiedl
    Jun 5 '16 at 19:09











  • I'm not sure I understand your comment... I'm using docker to manage my infrastructure. However, I'm not making nginx request files within the php application, I'm proxying to fpm to do so and I do need nginx to access static non-php files.

    – ThisIsErico
    Jun 5 '16 at 20:26











  • The files "reside in another container", i.e. not where nginx can see them, right?

    – Stefan Schmiedl
    Jun 5 '16 at 22:17











  • That's right @Stefan, they only get mounted as volumes in the webapp container, not in the nginx one.

    – ThisIsErico
    Jun 6 '16 at 4:48

















9















I'm trying to configure a php webapp using docker. The idea is to run the app using php-fpm in a standalone container and have another container that will run nginx. The idea for this setup is to use that same nginx container to proxy requests to other webapps that are already working on the same machine.
The problem is that I can't get nginx to properly process static files (js, css, etc.), as the requests to those keep going to fpm.



This is what the filesystem looks like:



/
├── Makefile
├── config
│ └── webapp.config
└── webapp
└── web
├── index.php
└── static.js


I'm running the whole thing using a Makefile that looks like this (not interested in docker-compose for this):



PWD:=$(shell pwd)
CONFIG:='/config'
WEBAPP:='/webapp'

run: | run-network run-webapp run-nginx

run-network:
docker network create internal-net

run-webapp:
docker run --rm
--name=webapp
--net=internal-net
--volume=$(PWD)$(WEBAPP):/var/www/webapp:ro
-p 9000:9000
php:5.6.22-fpm-alpine

run-nginx:
docker run --rm
--name=nginx
--net=internal-net
--volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
-p 80:80
nginx:1.11.0-alpine


This is what my config/webapp.conf looks like.



server 
listen 80;
server_name webapp.domain.com;

# This is where the index.php file is located in the webapp container
# This folder will contain an index.php file and some static files that should be accessed directly
root /var/www/webapp/web;

location /
try_files $uri $uri/ @webapp;


location @webapp
rewrite ^(.*)$ /index.php$1 last;


location ~ ^/index.php(/


Whatever action that needs to get processed using that index.php file will work. However, static files won't be served, resulting in nasty 404 errors (as the php webapp doesn't really have routes configured for those). I believe nginx tries to load those from its own container filesystem, when they are actually in the webapp container, failing back into @webapp.



Is there a way I can configure nginx to serve those files that reside in another container?










share|improve this question
















bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 3





    Are you using docker to isolate nginx from php applications while requiring that nginx has access to files within the php applications?

    – Stefan Schmiedl
    Jun 5 '16 at 19:09











  • I'm not sure I understand your comment... I'm using docker to manage my infrastructure. However, I'm not making nginx request files within the php application, I'm proxying to fpm to do so and I do need nginx to access static non-php files.

    – ThisIsErico
    Jun 5 '16 at 20:26











  • The files "reside in another container", i.e. not where nginx can see them, right?

    – Stefan Schmiedl
    Jun 5 '16 at 22:17











  • That's right @Stefan, they only get mounted as volumes in the webapp container, not in the nginx one.

    – ThisIsErico
    Jun 6 '16 at 4:48













9












9








9


0






I'm trying to configure a php webapp using docker. The idea is to run the app using php-fpm in a standalone container and have another container that will run nginx. The idea for this setup is to use that same nginx container to proxy requests to other webapps that are already working on the same machine.
The problem is that I can't get nginx to properly process static files (js, css, etc.), as the requests to those keep going to fpm.



This is what the filesystem looks like:



/
├── Makefile
├── config
│ └── webapp.config
└── webapp
└── web
├── index.php
└── static.js


I'm running the whole thing using a Makefile that looks like this (not interested in docker-compose for this):



PWD:=$(shell pwd)
CONFIG:='/config'
WEBAPP:='/webapp'

run: | run-network run-webapp run-nginx

run-network:
docker network create internal-net

run-webapp:
docker run --rm
--name=webapp
--net=internal-net
--volume=$(PWD)$(WEBAPP):/var/www/webapp:ro
-p 9000:9000
php:5.6.22-fpm-alpine

run-nginx:
docker run --rm
--name=nginx
--net=internal-net
--volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
-p 80:80
nginx:1.11.0-alpine


This is what my config/webapp.conf looks like.



server 
listen 80;
server_name webapp.domain.com;

# This is where the index.php file is located in the webapp container
# This folder will contain an index.php file and some static files that should be accessed directly
root /var/www/webapp/web;

location /
try_files $uri $uri/ @webapp;


location @webapp
rewrite ^(.*)$ /index.php$1 last;


location ~ ^/index.php(/


Whatever action that needs to get processed using that index.php file will work. However, static files won't be served, resulting in nasty 404 errors (as the php webapp doesn't really have routes configured for those). I believe nginx tries to load those from its own container filesystem, when they are actually in the webapp container, failing back into @webapp.



Is there a way I can configure nginx to serve those files that reside in another container?










share|improve this question
















I'm trying to configure a php webapp using docker. The idea is to run the app using php-fpm in a standalone container and have another container that will run nginx. The idea for this setup is to use that same nginx container to proxy requests to other webapps that are already working on the same machine.
The problem is that I can't get nginx to properly process static files (js, css, etc.), as the requests to those keep going to fpm.



This is what the filesystem looks like:



/
├── Makefile
├── config
│ └── webapp.config
└── webapp
└── web
├── index.php
└── static.js


I'm running the whole thing using a Makefile that looks like this (not interested in docker-compose for this):



PWD:=$(shell pwd)
CONFIG:='/config'
WEBAPP:='/webapp'

run: | run-network run-webapp run-nginx

run-network:
docker network create internal-net

run-webapp:
docker run --rm
--name=webapp
--net=internal-net
--volume=$(PWD)$(WEBAPP):/var/www/webapp:ro
-p 9000:9000
php:5.6.22-fpm-alpine

run-nginx:
docker run --rm
--name=nginx
--net=internal-net
--volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
-p 80:80
nginx:1.11.0-alpine


This is what my config/webapp.conf looks like.



server 
listen 80;
server_name webapp.domain.com;

# This is where the index.php file is located in the webapp container
# This folder will contain an index.php file and some static files that should be accessed directly
root /var/www/webapp/web;

location /
try_files $uri $uri/ @webapp;


location @webapp
rewrite ^(.*)$ /index.php$1 last;


location ~ ^/index.php(/


Whatever action that needs to get processed using that index.php file will work. However, static files won't be served, resulting in nasty 404 errors (as the php webapp doesn't really have routes configured for those). I believe nginx tries to load those from its own container filesystem, when they are actually in the webapp container, failing back into @webapp.



Is there a way I can configure nginx to serve those files that reside in another container?







nginx php-fpm docker static-content






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 14:57









Chad

1134




1134










asked Jun 5 '16 at 18:14









ThisIsEricoThisIsErico

14613




14613





bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.









  • 3





    Are you using docker to isolate nginx from php applications while requiring that nginx has access to files within the php applications?

    – Stefan Schmiedl
    Jun 5 '16 at 19:09











  • I'm not sure I understand your comment... I'm using docker to manage my infrastructure. However, I'm not making nginx request files within the php application, I'm proxying to fpm to do so and I do need nginx to access static non-php files.

    – ThisIsErico
    Jun 5 '16 at 20:26











  • The files "reside in another container", i.e. not where nginx can see them, right?

    – Stefan Schmiedl
    Jun 5 '16 at 22:17











  • That's right @Stefan, they only get mounted as volumes in the webapp container, not in the nginx one.

    – ThisIsErico
    Jun 6 '16 at 4:48












  • 3





    Are you using docker to isolate nginx from php applications while requiring that nginx has access to files within the php applications?

    – Stefan Schmiedl
    Jun 5 '16 at 19:09











  • I'm not sure I understand your comment... I'm using docker to manage my infrastructure. However, I'm not making nginx request files within the php application, I'm proxying to fpm to do so and I do need nginx to access static non-php files.

    – ThisIsErico
    Jun 5 '16 at 20:26











  • The files "reside in another container", i.e. not where nginx can see them, right?

    – Stefan Schmiedl
    Jun 5 '16 at 22:17











  • That's right @Stefan, they only get mounted as volumes in the webapp container, not in the nginx one.

    – ThisIsErico
    Jun 6 '16 at 4:48







3




3





Are you using docker to isolate nginx from php applications while requiring that nginx has access to files within the php applications?

– Stefan Schmiedl
Jun 5 '16 at 19:09





Are you using docker to isolate nginx from php applications while requiring that nginx has access to files within the php applications?

– Stefan Schmiedl
Jun 5 '16 at 19:09













I'm not sure I understand your comment... I'm using docker to manage my infrastructure. However, I'm not making nginx request files within the php application, I'm proxying to fpm to do so and I do need nginx to access static non-php files.

– ThisIsErico
Jun 5 '16 at 20:26





I'm not sure I understand your comment... I'm using docker to manage my infrastructure. However, I'm not making nginx request files within the php application, I'm proxying to fpm to do so and I do need nginx to access static non-php files.

– ThisIsErico
Jun 5 '16 at 20:26













The files "reside in another container", i.e. not where nginx can see them, right?

– Stefan Schmiedl
Jun 5 '16 at 22:17





The files "reside in another container", i.e. not where nginx can see them, right?

– Stefan Schmiedl
Jun 5 '16 at 22:17













That's right @Stefan, they only get mounted as volumes in the webapp container, not in the nginx one.

– ThisIsErico
Jun 6 '16 at 4:48





That's right @Stefan, they only get mounted as volumes in the webapp container, not in the nginx one.

– ThisIsErico
Jun 6 '16 at 4:48










3 Answers
3






active

oldest

votes


















0














I managed to solve the problem by mounting the webapp volume in the nginx container.
This is what the run-nginx job looks like now:



run-nginx:
docker run --rm
--name=nginx
--net=internal-net
--volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
--volume=$(PWD)$(WEBAPP)/web:/var/www/webapp/web:ro
-p 80:80
nginx:1.11.0-alpine


And this is the webapp.conf file, that will try to load the static files from the container and, if that's not possible will proxy the request to the fpm worker:



server png) 
try_files $uri $uri/;


location /
rewrite ^(.*)$ /index.php$1 last;


location ~ ^/index.php(/


However, I'd like to know if there's a better way to do so instead of sharing the same volume twice.
Thanks a lot!






share|improve this answer


















  • 4





    Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

    – Stefan Schmiedl
    Jun 6 '16 at 18:21


















0














Maybe this could be achieved using NFS



One docker container running NFS could be made where the code resides, which could be linked to the containers running nginx and php. The files would be stored in one container only.
This could provide another layer of isolation as well.






share|improve this answer






























    0














    I have two suggested options: The first one is to put your static assets in e.g. /static and instruct nginx to call a different backend service for those. Steps:



    1) Update your websites to point to /static/* for any static assets, so e.g. /styles.css becomes /static/styles.css



    2) Put your assets either in a separate container served by maybe another nginx (so you can reuse the container for several sites)



    3) Edit nginx.conf to send all requests to /static/* to the new container:



    location /static/ 
    proxy_pass http://static-container;



    The second option is to just move your static assets to a CDN, so you just need to update your website to load each static asset from an external URL (https://cdnwebsite/asdsadasda/styles.css instead of /styles.css or /static/styles.css)



    The second option has several advantages over the others, mainly around performance. A CDN will serve those faster and you're also working around the simultaneous connection limit a browser can make to each FQDN, so your page might load faster due to more simultaneous connections being used to load your site.






    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "2"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f782103%2fserve-static-content-using-docker-nginx-php-fpm%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I managed to solve the problem by mounting the webapp volume in the nginx container.
      This is what the run-nginx job looks like now:



      run-nginx:
      docker run --rm
      --name=nginx
      --net=internal-net
      --volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
      --volume=$(PWD)$(WEBAPP)/web:/var/www/webapp/web:ro
      -p 80:80
      nginx:1.11.0-alpine


      And this is the webapp.conf file, that will try to load the static files from the container and, if that's not possible will proxy the request to the fpm worker:



      server png) 
      try_files $uri $uri/;


      location /
      rewrite ^(.*)$ /index.php$1 last;


      location ~ ^/index.php(/


      However, I'd like to know if there's a better way to do so instead of sharing the same volume twice.
      Thanks a lot!






      share|improve this answer


















      • 4





        Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

        – Stefan Schmiedl
        Jun 6 '16 at 18:21















      0














      I managed to solve the problem by mounting the webapp volume in the nginx container.
      This is what the run-nginx job looks like now:



      run-nginx:
      docker run --rm
      --name=nginx
      --net=internal-net
      --volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
      --volume=$(PWD)$(WEBAPP)/web:/var/www/webapp/web:ro
      -p 80:80
      nginx:1.11.0-alpine


      And this is the webapp.conf file, that will try to load the static files from the container and, if that's not possible will proxy the request to the fpm worker:



      server png) 
      try_files $uri $uri/;


      location /
      rewrite ^(.*)$ /index.php$1 last;


      location ~ ^/index.php(/


      However, I'd like to know if there's a better way to do so instead of sharing the same volume twice.
      Thanks a lot!






      share|improve this answer


















      • 4





        Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

        – Stefan Schmiedl
        Jun 6 '16 at 18:21













      0












      0








      0







      I managed to solve the problem by mounting the webapp volume in the nginx container.
      This is what the run-nginx job looks like now:



      run-nginx:
      docker run --rm
      --name=nginx
      --net=internal-net
      --volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
      --volume=$(PWD)$(WEBAPP)/web:/var/www/webapp/web:ro
      -p 80:80
      nginx:1.11.0-alpine


      And this is the webapp.conf file, that will try to load the static files from the container and, if that's not possible will proxy the request to the fpm worker:



      server png) 
      try_files $uri $uri/;


      location /
      rewrite ^(.*)$ /index.php$1 last;


      location ~ ^/index.php(/


      However, I'd like to know if there's a better way to do so instead of sharing the same volume twice.
      Thanks a lot!






      share|improve this answer













      I managed to solve the problem by mounting the webapp volume in the nginx container.
      This is what the run-nginx job looks like now:



      run-nginx:
      docker run --rm
      --name=nginx
      --net=internal-net
      --volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro
      --volume=$(PWD)$(WEBAPP)/web:/var/www/webapp/web:ro
      -p 80:80
      nginx:1.11.0-alpine


      And this is the webapp.conf file, that will try to load the static files from the container and, if that's not possible will proxy the request to the fpm worker:



      server png) 
      try_files $uri $uri/;


      location /
      rewrite ^(.*)$ /index.php$1 last;


      location ~ ^/index.php(/


      However, I'd like to know if there's a better way to do so instead of sharing the same volume twice.
      Thanks a lot!







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jun 6 '16 at 16:40









      ThisIsEricoThisIsErico

      14613




      14613







      • 4





        Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

        – Stefan Schmiedl
        Jun 6 '16 at 18:21












      • 4





        Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

        – Stefan Schmiedl
        Jun 6 '16 at 18:21







      4




      4





      Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

      – Stefan Schmiedl
      Jun 6 '16 at 18:21





      Given your separation of nginx and php into different containers, I don't think so. You need the data in two different locations, you have to provide it twice. I'm very curious, too, if somebody comes up with a better idea.

      – Stefan Schmiedl
      Jun 6 '16 at 18:21













      0














      Maybe this could be achieved using NFS



      One docker container running NFS could be made where the code resides, which could be linked to the containers running nginx and php. The files would be stored in one container only.
      This could provide another layer of isolation as well.






      share|improve this answer



























        0














        Maybe this could be achieved using NFS



        One docker container running NFS could be made where the code resides, which could be linked to the containers running nginx and php. The files would be stored in one container only.
        This could provide another layer of isolation as well.






        share|improve this answer

























          0












          0








          0







          Maybe this could be achieved using NFS



          One docker container running NFS could be made where the code resides, which could be linked to the containers running nginx and php. The files would be stored in one container only.
          This could provide another layer of isolation as well.






          share|improve this answer













          Maybe this could be achieved using NFS



          One docker container running NFS could be made where the code resides, which could be linked to the containers running nginx and php. The files would be stored in one container only.
          This could provide another layer of isolation as well.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 28 '16 at 17:28









          MagarusuMagarusu

          101




          101





















              0














              I have two suggested options: The first one is to put your static assets in e.g. /static and instruct nginx to call a different backend service for those. Steps:



              1) Update your websites to point to /static/* for any static assets, so e.g. /styles.css becomes /static/styles.css



              2) Put your assets either in a separate container served by maybe another nginx (so you can reuse the container for several sites)



              3) Edit nginx.conf to send all requests to /static/* to the new container:



              location /static/ 
              proxy_pass http://static-container;



              The second option is to just move your static assets to a CDN, so you just need to update your website to load each static asset from an external URL (https://cdnwebsite/asdsadasda/styles.css instead of /styles.css or /static/styles.css)



              The second option has several advantages over the others, mainly around performance. A CDN will serve those faster and you're also working around the simultaneous connection limit a browser can make to each FQDN, so your page might load faster due to more simultaneous connections being used to load your site.






              share|improve this answer



























                0














                I have two suggested options: The first one is to put your static assets in e.g. /static and instruct nginx to call a different backend service for those. Steps:



                1) Update your websites to point to /static/* for any static assets, so e.g. /styles.css becomes /static/styles.css



                2) Put your assets either in a separate container served by maybe another nginx (so you can reuse the container for several sites)



                3) Edit nginx.conf to send all requests to /static/* to the new container:



                location /static/ 
                proxy_pass http://static-container;



                The second option is to just move your static assets to a CDN, so you just need to update your website to load each static asset from an external URL (https://cdnwebsite/asdsadasda/styles.css instead of /styles.css or /static/styles.css)



                The second option has several advantages over the others, mainly around performance. A CDN will serve those faster and you're also working around the simultaneous connection limit a browser can make to each FQDN, so your page might load faster due to more simultaneous connections being used to load your site.






                share|improve this answer

























                  0












                  0








                  0







                  I have two suggested options: The first one is to put your static assets in e.g. /static and instruct nginx to call a different backend service for those. Steps:



                  1) Update your websites to point to /static/* for any static assets, so e.g. /styles.css becomes /static/styles.css



                  2) Put your assets either in a separate container served by maybe another nginx (so you can reuse the container for several sites)



                  3) Edit nginx.conf to send all requests to /static/* to the new container:



                  location /static/ 
                  proxy_pass http://static-container;



                  The second option is to just move your static assets to a CDN, so you just need to update your website to load each static asset from an external URL (https://cdnwebsite/asdsadasda/styles.css instead of /styles.css or /static/styles.css)



                  The second option has several advantages over the others, mainly around performance. A CDN will serve those faster and you're also working around the simultaneous connection limit a browser can make to each FQDN, so your page might load faster due to more simultaneous connections being used to load your site.






                  share|improve this answer













                  I have two suggested options: The first one is to put your static assets in e.g. /static and instruct nginx to call a different backend service for those. Steps:



                  1) Update your websites to point to /static/* for any static assets, so e.g. /styles.css becomes /static/styles.css



                  2) Put your assets either in a separate container served by maybe another nginx (so you can reuse the container for several sites)



                  3) Edit nginx.conf to send all requests to /static/* to the new container:



                  location /static/ 
                  proxy_pass http://static-container;



                  The second option is to just move your static assets to a CDN, so you just need to update your website to load each static asset from an external URL (https://cdnwebsite/asdsadasda/styles.css instead of /styles.css or /static/styles.css)



                  The second option has several advantages over the others, mainly around performance. A CDN will serve those faster and you're also working around the simultaneous connection limit a browser can make to each FQDN, so your page might load faster due to more simultaneous connections being used to load your site.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 15:42









                  Pedro PerezPedro Perez

                  2,865167




                  2,865167



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Server Fault!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f782103%2fserve-static-content-using-docker-nginx-php-fpm%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to make RAID controller rescan devices The 2019 Stack Overflow Developer Survey Results Are InLSI MegaRAID SAS 9261-8i: Disk isn't recognized after replacementHow to monitor the hard disk status behind Dell PERC H710 Raid Controller with CentOS 6?LSI MegaRAID - Recreate missing RAID 1 arrayext. 2-bay USB-Drive with RAID: btrfs RAID vs built-in RAIDInvalid SAS topologyDoes enabling JBOD mode on LSI based controllers affect existing logical disks/arrays?Why is there a shift between the WWN reported from the controller and the Linux system?Optimal RAID 6+0 Setup for 40+ 4TB DisksAccidental SAS cable removal

                      Куамањотепек (Чилапа де Алварез) Садржај Становништво Види још Референце Спољашње везе Мени за навигацију17°19′47″N 99°1′51″W / 17.32972° СГШ; 99.03083° ЗГД / 17.32972; -99.0308317°19′47″N 99°1′51″W / 17.32972° СГШ; 99.03083° ЗГД / 17.32972; -99.030838877656„Instituto Nacional de Estadística y Geografía”„The GeoNames geographical database”Мексичка насељапроширитиуу

                      Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time? The 2019 Stack Overflow Developer Survey Results Are InHow is the altitude of a satellite defined, given that the Earth is not spherical?Why do satellites appear to move faster when overhead and slower closer to the horizon?For the mathematical relationship between J2 (km^5/s^2) and dimensionless J2 - which one is derived from the other?Why is Nodal precession affected by the rotational period of the planet?Why is it so difficult to predict the exact reentry location and time of a very low earth orbit object?Why are low earth orbit satellites not visible from the same place all the time?Perifocal coordinates and the orbit equationHow feasible is the Moonspike mission?What was the typical perigee after a shuttle de-orbit burn?I am having trouble calculating my classic orbital elements and am at a loss on where to lookAm I supposed to modify the gravitational constant with scale and why do fps & time scale changes cause my orbit to break?How Local time of a sun synchronous orbit is related to Right ascension of ascending node?What is wrong with my orbit sim equations? How can I fix them?How to obtain the initial positions and velocities of an inclined orbit?