Upstream setup with proxy and fastcgi?

Francis Daly francis at daoine.org
Mon Apr 18 22:35:44 MSD 2011


On Mon, Apr 18, 2011 at 01:45:54PM -0400, TECK wrote:

Hi there,

> [ 1.localserverip (main load balancer, with nginx and php-fpm installed)
> ]
> |
> ---- + [ 2.localserverip (node with php-fpm installed) ]
> |
> ---- + [ 3.localserverip (node with php-fpm installed) ]
> |
> ---- + [ 4.localserverip (node with php-fpm installed) ]
> 
> A better graphical example can be viewed in this image:
> http://farm6.static.flickr.com/5023/5631528237_9153f0d4a5_o.gif

There's still something of a lack of explicitness here. The words show one
nginx (load balancing) http server plus four php-fpm fastcgi servers. The
picture shows the load balancer plus multiple web servers.

Putting them together, what I *think* you have is:

one nginx http server which does the load balancing, plus

many nginx http servers which do file serving, plus

many php-fpm fastcgi servers which do php processing,

where each fastcgi server is on the same machine as a file-serving nginx;
and also one of the file-serving nginx servers is on the same machine
as the load-balancing nginx server.

> Basically, 1.localserverip is the site entrance, where nginx load
> balancing is done.
> Each server (including the 1.localserverip) will have the exact same
> content into /var/www/html directory.
> The served content consist in static (images, cass, js, etc.) and php
> files.

Igor mentions "don't load-balance static stuff".

If you want to do it anyway, for failover reasons for example, then the
load-balancing nginx server would have something like

 location / {
  proxy_pass http://proxy;
 }

and the file-serving nginx servers would just have something like

 root /var/www/html;

> My goal is to be able to load balance not only the proxy but also the
> fastcgi.
> What would be the configuration like?

There are two different ways you can do this.

If you decide "load balancer shall know about fastcgi", then you will
have something like

 location [php urls] {
  fastcgi_pass php;
 }

where [php urls] is the appropriate string or regex. That will be on
the load-balancing nginx server; the file-serving nginx servers won't
have any mention of fastcgi.

Alternatively, you could let the file-serving nginxen handle fastcgi --
in that case, the load balancer would have

 location / {
  proxy_pass http://proxy;
 }

and the file servers would have

 location [php urls] {
   fastcgi_pass this_php_server;
 }

It's an extra level of proxying for the fastcgi stuff, and it means that
one http server is pretty much tied to one fastcgi server; but since the
fastcgi server is accessing the same filesystem as the http server, the
"-e $filename" and other file-related cleverness in nginx can work.

I suggest just setting up a quick test, and seeing if one plan doesn't
work well enough for you.

Good luck,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list