Issue w/ nginx in hybrid static/php load balancer scenario

Denis S. Filimonov den.lists at gmail.com
Mon Feb 11 06:28:09 MSK 2008


I'd try something like the following:

location / {
    if ($request_filename !~ "(\.php|/)$") {
    	proxy_pass http://static-pool/website/htdocs/;
    }
}

set $dir_index index.php;

location ~ /$ {
	set $index_php $root$uri$dir_index;
	if (-f $index_php) {
		fastcgi_pass    php-fcgi-pool;
		break;
	}
	proxy_pass http://static-pool/website/htdocs/;
}

location ~ \.php$ {
     fastcgi_pass    php-fcgi-pool;
}

On Sunday 10 February 2008 18:41:18 Mike Javorski wrote:
> I tried that (iirc). The issue is that location / is processed first
> (since it's not a regex). but the regex doesn't seem to apply after
> the index file options are tacked on the end.
>
> On Feb 10, 2008 12:14 PM, Kiril Angov <kupokomapa at gmail.com> wrote:
> > Why don't you put
> >
> >  location ~ \.php$ {
> >     fastcgi_pass    php-fcgi-pool;
> >  }
> >
> >
> > before "location /" so that it can match first?
> >
> > Kupo
> >
> > On Feb 10, 2008 1:51 AM, Mike Javorski <mike.javorski at gmail.com> wrote:
> > > Thanks Denis. The problem w/ your solution is there is lots of
> > > directories. I don't want to have to create entries for each. I
> > > suppose I could to a regex for .*/$ but some of the directories have
> > > index.html instead of index.php, and I need to support that as well
> > >
> > > :-(.
> > >
> > > Any other options/suggestions?
> > >
> > > - mike
> > >
> > > On Feb 9, 2008 10:42 PM, Denis F. Latypoff <denis at gostats.ru> wrote:
> > > > Hello Mike,
> > > >
> > > > Sunday, February 10, 2008, 12:32:14 PM, you wrote:
> > > > > I have nginx set up as a load balancer in front of two machines
> > > > > running fastcgi/php, and nginx for static content. The desired goal
> > > > > is to have all php pages (including the site index pages of
> > > > > .*/index.php) processed by the fastcgi/php upstream, and everything
> > > > > else provided by the static servers. The following is what I have
> > > > > and what I believe should have worked, but it appears to run all
> > > > > directory paths via the static rule, rather than the php rule which
> > > > > matches the index.
> > > > >
> > > > > To sum up:
> > > > > / -- via static system (WRONG)
> > > > > /index.php -- via fastcgi/php system (RIGHT)
> > > > > /blah/ -- via static system (WRONG)
> > > > > /blah/index.php -- via fastcgi/php system (RIGHT)
> > > > >
> > > > > nginx version is 0.6.25, Help! :-)
> > > > >
> > > > > tia,
> > > > >
> > > > > - mike
> > > > >
> > > > > My Config File (the relevent bits anyway):
> > > > > ---------------------------------------------------
> > > > >
> > > > > http {
> > > > >     upstream  static-pool {
> > > > >         server  192.168.7.40:80;
> > > > >         server  192.168.7.41:80;
> > > > >     }
> > > > >
> > > > >     upstream php-fcgi-pool {
> > > > >         server  192.168.7.40:7000;
> > > > >         server  192.168.7.41:7000;
> > > > >     }
> > > > >
> > > > >     server {
> > > > >         listen  80;
> > > > >         root    /website/htdocs;
> > > > >         index   index.php;
> > > > >         fastcgi_index   index.php;
> > > > >         include     /etc/nginx/fastcgi_params;
> > > > >
> > > > >         location / {
> > > > >             proxy_pass http://static-pool/website/htdocs/;
> > > > >         }
> > > >
> > > > +         location = / {
> > > > +             fastcgi_pass    php-fcgi-pool;
> > > > +         }
> > > >
> > > > +         location = /blah/ {
> > > > +             fastcgi_pass    php-fcgi-pool;
> > > > +         }
> > > >
> > > > >         location ~ \.php$ {
> > > > >             fastcgi_pass    php-fcgi-pool;
> > > > >         }
> > > > >     }
> > > > > }
> > > >
> > > > --
> > > > Best regards,
> > > >  Denis                            mailto:denis at gostats.ru
-- 
Denis.





More information about the nginx mailing list