Aug 06

nginx – how location directive match performed

i am new to nginx! i tried to config nginx to server php only from site root,and only some php file to be excuted from a sub – directory. i need to get more detail about location.

This directive allows different configurations depending on the URI. It can be configured using both literal strings and regular expressions. To use regular expressions, you must use a prefix:

  1. “~” for case sensitive matching
  2. “~*” for case insensitive matching
  3. there is no syntax for NOT matching a regular expression. Instead, match the target regular expression and assign an empty block, then use location / to match anything else.

The order in which location directives are checked is as follows:

  1. Directives with the “=” prefix that match the query exactly (literal string). If found, searching stops.
  2. All remaining directives with conventional strings. If this match used the “^~” prefix, searching stops.
  3. Regular expressions, in the order they are defined in the configuration file.
  4. If #3 yielded a match, that result is used. Otherwise, the match from #2 is used.

i want to block access to any script to member directory,but allow access to /member/a.php and /member/b.php.

Source code    
server
      {
          listen       80;
          server_name abcdomain.com;
          index index.html index.htm index.php default.html default.htm default.php;
          root  /html/abcdomain.com;
          location ~ /member/(a|b)\.(php|php5)
            {
                try_files $uri =404;
               fastcgi_pass  127.0.0.1:60009;
               include fastcgi.conf;
           }
         location ~ /member/.*\.(php|php5)
           {
               deny all;
           }
         location ~ .*\.(php|php5)?$
             {
                 try_files $uri =404;
                 fastcgi_pass  127.0.0.1:60009;
                 fastcgi_index index.php;
                 include fastcgi.conf;
             }
         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
             {
                 expires      30d;
             }
         location ~ .*\.(js|css)?$
             {
                 expires      12h;
             }
    }