<blockquote>
  <p>Problem is in resources - I see that each app container has own nginx instance, and server (VPS) must have global nginx, working as reverse proxy for containers.</p>
</blockquote>

<p>Generally speaking yes, this is how this sort of thing goes.  It's more of an issue for PHP than other languages because PHP doesn't really have a standalone application server, but instead is commonly deployed using php-fpm with nginx.  Since php-fpm supports communication via TCP sockets, theoretically you could run only fpm in the containers and have nginx on the host talk to fpm across the Docker networking layer, but I haven't researched this option enough to be convinced it would work.</p>

<p>Docker makes the most sense when used within the context of an orchestration layer like Kubernetes.  Rather than running several Docker containers manually or semi-manually on a particular host, you would schedule them with kubernetes and it would distribute them across its cluster of nodes - the specific machine that runs the container becomes irrelevant.  The kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service</a> then provides you with an IP via kube-proxy that load-balances across the pods of that service.</p>

CC BY-SA 4.0
2018-11-21T23:18:52.493Z
2018-11-21T23:18:52.493Z
Xiong Chiamiov
<p>you can run one container serving Nginx for others, a container is no different from a server/VM if there is not a specific reason for each container having Nginx. you should clarify why you have one global Nginx and other nodes having Nginx, assume you do not have containers. You say the problem is resources, I am not sure your problem is the way Nginx work or with your design.</p>

CC BY-SA 4.0
2018-11-06T12:07:28.130Z
2018-11-06T12:07:28.130Z
hakkican
<p>I am going to deploy my app to production on VPS server, using Docker. My goal is stable version from latest tag at <code>example.com</code>, and dev version from dev tag at <code>dev.example.com</code>.</p>

<p>Because this is an PHP application, container has own nginx+php set. I don't know how - if it's even possible (without Swoole in PHP etc.) to avoid this.</p>

<p>Problem is in resources - I see that each app container has own nginx instance, and server (VPS) must have global nginx, working as reverse proxy for containers. </p>

<p>Is there are any better way to archieve my goals?
Thanks!</p>

CC BY-SA 4.0
2018-11-05T23:49:53.937Z
I don't know much about docker, so I can't provide an answer that is helpful. However I know you can build whole servers just serving PHP and use nginx as a proxy, so it should certainly be possible to do the same with docker. Your  static files need to be served somehow, not sure if it would be better to have nginx for that in the docker container or make sure they are on external cdn
jdog
<docker><nginx><php>
Multi-container server of PHP apps with reverse proxy?
aso
# Multi-container server of PHP apps with reverse proxy?

(Asked by: username_0 on 2018-11-05)

I am going to deploy my app to production on VPS server, using Docker. My goal is stable version from latest tag at `example.com`, and dev version from dev tag at `dev.example.com`.

Because this is an PHP application, container has own nginx+php set. I don't know how - if it's even possible (without Swoole in PHP etc.) to avoid this.

Problem is in resources - I see that each app container has own nginx instance, and server (VPS) must have global nginx, working as reverse proxy for containers.

Is there are any better way to archieve my goals?
Thanks!

**Tags:** docker, nginx, php

> **Comments:**
> **username_1**: I don't know much about docker, so I can't provide an answer that is helpful. However I know you can build whole servers just serving PHP and use nginx as a proxy, so it should certainly be possible to do the same with docker. Your  static files need to be served somehow, not sure if it would be better to have nginx for that in the docker container or make sure they are on external cdn  

---

## 2 answers

### Answer by username_2 on 2018-11-21. Score: 1

> Problem is in resources - I see that each app container has own nginx instance, and server (VPS) must have global nginx, working as reverse proxy for containers.

Generally speaking yes, this is how this sort of thing goes. It's more of an issue for PHP than other languages because PHP doesn't really have a standalone application server, but instead is commonly deployed using php-fpm with nginx. Since php-fpm supports communication via TCP sockets, theoretically you could run only fpm in the containers and have nginx on the host talk to fpm across the Docker networking layer, but I haven't researched this option enough to be convinced it would work.

Docker makes the most sense when used within the context of an orchestration layer like Kubernetes. Rather than running several Docker containers manually or semi-manually on a particular host, you would schedule them with kubernetes and it would distribute them across its cluster of nodes - the specific machine that runs the container becomes irrelevant. The kubernetes [service](https://kubernetes.io/docs/concepts/services-networking/service/) then provides you with an IP via kube-proxy that load-balances across the pods of that service.


---

### Answer by username_3 on 2018-11-06. Score: 0

you can run one container serving Nginx for others, a container is no different from a server/VM if there is not a specific reusername_0n for each container having Nginx. you should clarify why you have one global Nginx and other nodes having Nginx, assume you do not have containers. You say the problem is resources, I am not sure your problem is the way Nginx work or with your design.


---

