Not existant files passed to php backend
Igor Sysoev
is at rambler-co.ru
Wed Aug 20 21:53:06 MSD 2008
On Thu, Aug 21, 2008 at 12:24:29AM +0800, Delta Yeh wrote:
> Does the following config work?
> If it does, is it reasonable in your opinition?
>
> location / {
>
> if($geo ) {
> proxy_pass http://upstream2;
> }
>
> if( $request_uri ~ \.css$){
> expire 3d;
> }
>
> if( $request_uri ~ \.gif$ ) {
> expire 1d;
> }
> ...
> if( $request_uri ~ \.jpeg$ ) {
> expire 2d;
> }
>
> if( $request_uri ~ /admin/ ) {
> auth_basic "Restricted";
> auth_basic_user_file conf/htpasswd;
>
> }
>
>
> proxy_pass http://upstream;
>
> }
No, it will not work as you expect. This is the reason why I do not
recommend to use complex "if" blocks: it simply does not work as one may
expect due to internal implementation.
This was my big mistake when I had allowed some directives inside
"if" blocks. It was better to postpone it before good "if" implementation.
And one note again: never use
if( $request_uri ~ \.jpeg$ ) {
there is the best replacement:
location ~ \.jpeg$ {
> 2008/8/21 Igor Sysoev <is at rambler-co.ru>:
> > On Thu, Aug 21, 2008 at 12:01:42AM +0800, Delta Yeh wrote:
> >
> >> Does multiple complex directive inside "if" block impact the performance ?
> >> If so, how much ?
> >
> > No, they does not impact the perfomance, but they has many limits
> > and drawbacks.
> >
> >> 2008/8/20 Igor Sysoev <is at rambler-co.ru>:
> >> > On Wed, Aug 20, 2008 at 05:29:00PM +0200, Roxis wrote:
> >> >
> >> >> On Wednesday 20 August 2008, Reinis Rozitis wrote:
> >> >> > > it is expected
> >> >> > >
> >> >> > > if you don't like php's 404 page
> >> >> > > set fastcgi_intercept_errors to on
> >> >> >
> >> >> > I see.
> >> >> >
> >> >> > Just switching from lighty where the default behaviour is first to check
> >> >> > the local file ( lighttpd has an extra setting 'check-local' where you can
> >> >> > specify to look for the file on local disk rather than blindly forwarding
> >> >> > to request on the fastcgi backend )
> >> >> >
> >> >> > Although this is handy in case of remote fastcgi backends isnt the majority
> >> >> > setups where the nginx and php (and other fastcgi processes) are on the
> >> >> > same box? And as the php is the slowest component wouldnt it be more
> >> >> > efficient from the performance point of view for the nginx throw the error
> >> >> > first rather than intercepting the error later (and maybe add a
> >> >> > setting/feature (mimic to lighty) to disable the local file check)..
> >> >> >
> >> >> > Anyways thx for the hint.
> >> >> >
> >> >> > rr
> >> >>
> >> >> you can use ngx_http_rewrite_module
> >> >>
> >> >> if (!-f $request_filename) {
> >> >> return 404;
> >> >> }
> >> >> fastcgi_pass ...
> >> >>
> >> >> but it's not recommended
> >> >
> >> > Although I generally do not recommend to use "if (!-f $request_filename)",
> >> > it's mostly related to complex directive inside "if" block, something like:
> >> >
> >> > if (!-f $request_filename) {
> >> > fastcgi_pass ...
> >> > }
> >> >
> >> > but simple "return 404" in "if" block is OK.
> >> >
> >> >
> >> > --
> >> > Igor Sysoev
> >> > http://sysoev.ru/en/
> >> >
> >> >
> >
> > --
> > Igor Sysoev
> > http://sysoev.ru/en/
> >
> >
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list