ソースを参照

refactor nginx rewrite rules

Jason Hinkle 12 年 前
コミット
fceeb5233c
2 ファイル変更19 行追加23 行削除
  1. 8 13
      phreeze/deploy/ngnix.conf
  2. 11 10
      phreeze/libs/verysimple/Phreeze/GenericRouter.php

+ 8 - 13
phreeze/deploy/ngnix.conf

@@ -58,29 +58,24 @@ http {
         #location ~ \.php$ {
         #    proxy_pass   http://127.0.0.1;
         #}
+        
+        root /home/ubuntu/FrameworkBenchmarks/;
+        index  index.php;
+        
+        location /phreeze/ {
+            try_files $uri $uri/ /phreeze/index.php?_REWRITE_COMMAND=$uri&$args;
+        }
 
         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         #
         location ~ \.php$ {
-            root /home/ubuntu/FrameworkBenchmarks;
+            try_files $uri =404;
             fastcgi_pass   127.0.0.1:9001;
             fastcgi_index  index.php;
 #            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        /usr/local/nginx/conf/fastcgi_params;
         }
-
-	    # url rewriting for a Phreeze application called "example" 
-	    #
-	    location ~ ^/phreeze/(.*) {
-	        try_files /phreeze/$1 /phreeze/$1/ /phreeze/index.php?_REWRITE_COMMAND=$1&args;
-	    }
-	    
-	    # url rewriting for phreeze app that is installed in the htdocs root
-	    #
-	    #location ~ ^/(.*) {
-	    #    try_files /$1 /$1/ /index.php?_REWRITE_COMMAND=$1&args;
-	    #}
     
         # deny access to .htaccess files, if Apache's document root
         # concurs with nginx's one

+ 11 - 10
phreeze/libs/verysimple/Phreeze/GenericRouter.php

@@ -3,16 +3,17 @@
 
 /** import supporting libraries */
 require_once('IRouter.php');
+require_once('verysimple/HTTP/RequestUtil.php');
 
-/**
+/**
  * Generic Router is an implementation of IRouter that uses patterns to connect
- * routes to a Controller/Method
- *
- * @package    verysimple::Phreeze
- * @author     VerySimple Inc.
- * @copyright  1997-2012 VerySimple, Inc.
- * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
- * @version    1.0
+ * routes to a Controller/Method
+ *
+ * @package    verysimple::Phreeze
+ * @author     VerySimple Inc.
+ * @copyright  1997-2012 VerySimple, Inc.
+ * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
+ * @version    1.0
  */
 class GenericRouter implements IRouter
 {
@@ -132,8 +133,8 @@ class GenericRouter implements IRouter
 			// if a root folder was provided, then we need to strip that out as well
 			if ($this->appRootUrl)
 			{
-				$prefix = $this->appRootUrl.'/';
-				while (substr($this->uri,0,strlen($prefix)) == $prefix)
+				$prefix = str_replace(RequestUtil::GetServerRootUrl(),'/',$this->appRootUrl);
+				if (substr($this->uri,0,strlen($prefix)) == $prefix)
 				{
 					$this->uri = substr($this->uri,strlen($prefix));
 				}