need help cleaning up user directory and php rules

Igor Sysoev is at rambler-co.ru
Sat Mar 14 22:28:39 MSK 2009


On Sat, Mar 14, 2009 at 09:33:43PM +0300, Igor Sysoev wrote:

> On Sat, Mar 14, 2009 at 11:25:10AM -0700, mike wrote:
> 
> > Is all you want the ability to have
> > 
> > foo.com/~username/ ?
> > 
> > If so I have it working a lot easier. Well, at least for ~mike. But
> > with the new regex location/etc. support it might be able to work
> > without that.
> > 
> > something like
> > 
> > location ^/~(.+) {
> >          root /home/$1/public_html/;
> > }
> > 
> > Perhaps? Not sure. I should probably try it but I'm too lazy. Igor
> > would probably know how to hack it quick.
> 
> It should be:
> 
>  location ^/~(.+?)(/.+)?$ {
>           alias  /home/$1/public_html$2;
>  }

The location should be

-  location ^/~(.+?)(/.+)?$ {
+  location ^/~(.+?)(/.*)?$ {

Also I have found two bugs in alias captures, the patch is attached.


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/http/ngx_http_core_module.c
===================================================================
--- src/http/ngx_http_core_module.c	(revision 1884)
+++ src/http/ngx_http_core_module.c	(revision 1886)
@@ -1378,13 +1378,15 @@
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                            "test location: ~ \"%V\"", &(*clcfp)->name);
 
-            if ((*clcfp)->captures && r->captures == NULL) {
+            if ((*clcfp)->captures) {
 
                 len = (NGX_HTTP_MAX_CAPTURES + 1) * 3;
 
-                r->captures = ngx_palloc(r->pool, len * sizeof(int));
                 if (r->captures == NULL) {
-                    return NGX_ERROR;
+                    r->captures = ngx_palloc(r->pool, len * sizeof(int));
+                    if (r->captures == NULL) {
+                        return NGX_ERROR;
+                    }
                 }
             }
 
@@ -1672,13 +1674,11 @@
         return NULL;
     }
 
-    reserved += r->uri.len - alias + 1;
-
     if (clcf->root_lengths == NULL) {
 
         *root_length = clcf->root.len;
 
-        path->len = clcf->root.len + reserved;
+        path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
 
         path->data = ngx_pnalloc(r->pool, path->len);
         if (path->data == NULL) {
@@ -1688,7 +1688,7 @@
         last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
 
     } else {
-        if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
+        if (ngx_http_script_run(r, path, clcf->root_lengths->elts, ++reserved,
                                 clcf->root_values->elts)
             == NULL)
         {


More information about the nginx mailing list