Performance question regarding regex

Dear forums/mailing list,

just a quick question:

[code]location / {
root /home/folder/www;
index index.php;
#if (!-e $request_filename) {
if ($request_filename !~*
^.+.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf)$)
{
#rewrite ^(.)$ /index.php?q=$1 last;
rewrite ^.
$ /index.php last;
break;
}
root /home/folder/www;
expires 30d;
break;
}

[/code]

What would be faster here. Using the commented “#if (!-e
$request_filename) {” or the explicit filetype matching?

Thank you in advance!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,109438,109438#msg-109438

Sorry, forgot to add that Zend Framework is used here, so any dynamic
request would pass “if (!-e $request_filename) {” because it’s ending
with “/”.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,109438,109439#msg-109439

On Thu, Jul 15, 2010 at 09:18:33PM -0400, panni wrote:

        {

What would be faster here. Using the commented “#if (!-e
$request_filename) {” or the explicit filetype matching?

The better will be

root /home/folder/www;

location / {
index index.php;
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME /home/folder/www/index.php;
include fastcgi_params;
}

location ~*
.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf)$
{
expires 30d;
}

or

root /home/folder/www;

location / {
try_files $uri $uri/ @php;
index index.php;
expires 30d;
}

location .php$ {
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME /home/folder/www$uri;
include fastcgi_params;
}

location @php {
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME /home/folder/www/index.php;
include fastcgi_params;
}


Igor S.
http://sysoev.ru/en/

Hey, thank you for your answer.

try_files only seems to hit when a root directive is set in the config.
try_files only works on /home/www$uri files, not on /www/html$uri
files.
Is this intended? How can I make it work when a file called
/www/html/asdf.php is requested by /asdf.php?

location / {
            root /home/www;
            try_files $uri "/www/html$uri" @ksphp;

            if ($request_filename ~* \.(js|css)$) {
                return 404;
            }

            index index.php;
            expires 30d;
        }

Thank you!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,109438,114603#msg-114603

On Thu, Jul 29, 2010 at 07:44:54PM -0400, panni wrote:

Hey, thank you for your answer.

try_files only seems to hit when a root directive is set in the config.
try_files only works on /home/www$uri files, not on /www/html$uri
files.
Is this intended? How can I make it work when a file called
/www/html/asdf.php is requested by /asdf.php?

     root /;
     try_files  home/www$uri www/html$uri  @ksphp;

but probably it’s better to use:

location = /asdf.php {
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME /www/html$uri;

}

    }

Do not use “if ($request_filename”:

location / {
root /home/www;
try_files $uri @ksphp;

index index.php;
expires 30d;

}

location ~* .(js|css)$ {
return 404;
}


Igor S.
http://sysoev.ru/en/

Thank you again for your quick answer.

Igor S. Wrote:

Is this intended? How can I make it work when a
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME
/www/html$uri;

}

Is try_files over three possible locations that slow or why are you
suggesting the directive for the literal string?

index index.php;
expires 30d;

}

location ~* .(js|css)$ {
return 404;
}

Thank you. But why would you do this rather than an if clause? If its
faster, or my way a no-go, do you have some sort of compendium of do’s
and don’ts in NGINX?


Igor S.
http://sysoev.ru/en/


nginx mailing list
[email protected]
http://nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,109438,114822#msg-114822

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs